C++ Logo

std-proposals

Advanced search

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

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sun, 7 Apr 2024 18:45:09 +0200
On 07/04/2024 15.35, Frederick Virchanza Gotham via Std-Proposals wrote:
> We need more information in std::type_info, such as the 'sizeof' and
> 'alignof' of a type, and also if it's polymorphic. We could probably
> do with a few more pieces of information too (Is it a pointer? Is it
> an integer type?).
>
> Here's a very early draft paper just to stir conversation:
>
> http://www.virjacode.com/papers/extend_type_info.htm
>
> I'm looking at the Itanium ABI spec here . . . and I'll look closer
> over the coming days but I can't see the 'sizeof' nor the 'alignof'
> anywhere, so I don't know how much extra info we can garner here???
>
> If an ABI break is inevitable then we might even need an
> "std::typeid_extended" which returns a "std::type_info_extended".
>
> By the way... while I'm typing away here. . . since you need to
> include the <typeinfo> header in order to use the 'typeid' operator,
> would it not have made more sense to have had a standard library
> function instead of an operator, as follows:
>
> namespace std {
> template<typename T>
> constexpr type_info const &typeid(void) noexcept;
> }
>
> And so then you would have done:
>
> auto const &ti = std::typeid<MyClass>();

How would that allow to determine the type of a
polymorphic object, where only a pointer-to-base
might be given?

Jens

Received on 2024-04-07 16:45:17