C++ Logo


Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Thu, 11 Apr 2024 09:40:30 -0400
On Thu, Apr 11, 2024 at 9:32 AM Mihail Mihaylov via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Thu, Apr 11, 2024 at 4:14 PM Gašper Ažman <gasper.azman_at_[hidden]>
> wrote:
>> dynamic_cast structures are only included for types with a vtable.
> And a compile-time list of base types is included for... no types at all.
> Whatever the actual implementation, it will require something which isn't
> currently available.
> All I'm saying is that asking for `any` to support taking out an instance
> of a base class instead of the actual class stored in it is not
> unreasonable.

If you want to make a type-erased `my::Any` where one of the type-erased
affordances is "any_cast to base," that's totally possible.
I show exactly how to do it in my "Back to Basics: Type Erasure"
<https://www.youtube.com/watch?v=tbUCHifyT24&t=2210s> from 2019.
Basically, *any operation you can think of* can be turned into an
affordance and type-erased, as long as you're willing to write your own
type-erased type. (Which is easy and everyone should know how to do it. :)
See "Type-erased UniquePrintable and PrintableRef"
<https://quuxplusone.github.io/blog/2020/11/24/type-erased-printable/> from
November 2020.)


Received on 2024-04-11 13:40:44