I have a variadic Engine template class:
template class Engine;
I\'d like to assign a number to each compon
UNTESTED:
template
constexpr int index_of() { return -1; } // type not found
template
constexpr int index_of() {
return std::is_same::value ? N : index_of();
}
template
template
constexpr int engine::ordinal() {
return index_of<0, Component, Components...>();
}
I could have used structs, but I find this much cleaner (without all the ::type
ugliness).
If you want a compile-time error when the type is not found, change ordinal
to:
template
template
constexpr int engine::ordinal() {
static_assert(index_of<0, Component, Components...>()!=-1, "invalid component");
return index_of<0, Component, Components...>();
}