I'm rolling my own entity component system.
Is there a way of mapping struct types to integers?
I could implement a toInt()
for each struct, but it feels inelegant to execute code to get a number which could be known at compile-time.
I'm rather not take care of the numbering myself (it doesn't need to be stable) and just "register" a handful of struct types with a "numberer" at compile time.
I'm looking for an API along the lines of:
struct Foo {
...
}
struct Bar {
...
}
struct Baz {
...
}
struct Quux {
...
}
register!(Foo, Bar, Baz);
numberOf!(Foo) == 0;
numberOf!(Bar) == 1;
numberOf!(Baz) == 2;
numberOf!(Quux) == failure of some kind;
Is there a way of doing this?