[Bug c++/100157] Support `__type_pack_element` like Clang
m.cencora at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 30 11:44:01 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100157
--- Comment #5 from m.cencora at gmail dot com ---
Yeah, __is_same builtin beats custom unique-id comparisons, but it is available
only since gcc-10 so unavailable for me.
Recently I discovered this one (only works for unique types), and it is twice
as fast as __is_same in my scenarios (I guess mainly due to memoization):
template <typename T>
struct indexed_type
{
unsigned idx;
};
template <typename ...Ts>
struct indexed_type_list : indexed_type<Ts>...
{
constexpr indexed_type_list(unsigned i = 0)
: indexed_type<Ts>{i++}...
{}
};
template <typename ...Ts>
constexpr indexed_type_list<Ts...> indexed_type_list_instance;
template <typename T, typename ...Ts>
constexpr auto index_of =
static_cast<indexed_type<T>>(indexed_type_list_instance<Ts...>).idx;
Anyway, thanks for working on this topic!
More information about the Gcc-bugs
mailing list