C++ Logo


Advanced search

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

From: Phil Endecott <std_proposals_list_at_[hidden]>
Date: Fri, 12 Apr 2024 19:51:35 +0100
Mihail Mihaylov wrote:
> 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.

You can, however, usefully store pointers to polymorphic types in std::any.
Storing a Derived* and asking the any if it contains a Base* is what I wanted
to do.

(Actually something more like a weak_ptr<Derived>, but maybe I
shouldn't mention that, it's just adding another level of complexity into
this discussion.)

Regards, Phil.

Received on 2024-04-12 18:51:37