C++ Logo


Advanced search

Re: [std-proposals] Extend std::type_info with more information

From: Mihail Mihaylov <mihail.mihailov_at_[hidden]>
Date: Fri, 12 Apr 2024 17:34:19 +0300
On Fri, Apr 12, 2024 at 1:52 PM Mihail Mihaylov <
mihail.mihailov_at_[hidden]> wrote:

> OK, you convinced me (kind of). I've been working for years in a code base
> that has its own any-like object, but I haven't really used `std::any`
> itself. It took me a while to realize how significant it is that `any_cast`
> returns a copy instead of a reference. It now seems to me that the
> designers of `std/boost::any` never meant for polymorphic types to be
> stored in it and the question about how to get a base out of the stored
> derived value goes outside of its intended usage.

Scratch that, it turns out that `any_cast<A>(any*)` returns an `A*` to the
value inside, which makes it meaningful to request the ability for this
overload to return a non-null `A*` when the `any` contains a `B` where `B`
is derived from `A`.

This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

Received on 2024-04-12 14:34:33