How can I get the index of a type in a variadic class template?
问题 I have a variadic Engine template class: template <typename ... Components> class Engine; I'd like to assign a number to each component at compile time which is equivalent to their ordering. This would be returned when making the following call: template <typename Component> int ordinal(); So for example if: Engine<PositionComponent, PhysicsComponent, InputComponent> engine; was declared, the call: engine.ordinal<PhysicsComponent>(); would return 1 and a similar call with InputComponent