C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 7 Apr 2024 14:35:10 +0100
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>();

The ship has sailed but anyway.

Received on 2024-04-07 13:35:19