我有几种类型,我想std::integral_constant在编译时将一个顺序ID值"绑定" 到每个类型.
例:
struct Type00 { };
struct Type01 { };
struct Type02 { };
struct Type03 { };
struct TypeXX { };
struct TypeYY { };
template<typename T> struct TypeInfo
{
using Id = std::integral_constant<int, ???>;
};
int main()
{
cout << TypeInfo<Type00>::Id::value; // Should always print 0
cout << TypeInfo<Type01>::Id::value; // Should always print 1
cout << TypeInfo<Type02>::Id::value; // Should always print 2
cout << TypeInfo<Type03>::Id::value; // Should always print 3
cout << TypeInfo<TypeXX>::Id::value; // Should …Run Code Online (Sandbox Code Playgroud)