Compile-time template `std::integral_constant` counter - how to implement it?
问题 I have several types and I want to "bind" an std::integral_constant sequential ID value to every type at compile-time. Example: 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: