C++ Logo


Advanced search

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

From: Mihail Mihaylov <mihail.mihailov_at_[hidden]>
Date: Thu, 11 Apr 2024 14:23:39 +0300
On Thu, Apr 11, 2024 at 2:03 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:

> Step 1 of implementing it is to be able to see all of the base classes
> of the Derived type at runtime having only its type_info. So I propose
> adding a new method called 'bases' to std::type_info. At first I
> thought this new method should return a pointer to a null-terminated
> array of pointers to type_info's, as follows:
> std::type_info const *const *type_info::bases(void) const noexcept;
> But Microsoft's array of type_info's isn't laid out the same way as
> Itanium's. So we need a special iterator to compensate for this,
> "class type_info_iterator", and so the method 'bases' returns a pair
> of iterators [first,last) to the type_info's of all the base classes.
> I've written it into my paper with implementations for Microsoft and
> Itanium:
> http://www.virjacode.com/papers/extend_type_info.htm
> And also implemented it on GodBolt:
> https://godbolt.org/z/fbTvbTK11

I think there is another option which might be simpler. A
`dynamic_upcast()` function where all the source type information is passed
at runtime would make implementing `any_upcast()` trivial. It's prototype
could be:

template<typename T> T* dynamic_upcast(void *ptr, const type_info& type);

My guess is that the implementation of such a function could reuse big
parts of the implementation of the preexisting dynamic_cast.

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-11 11:23:52