Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdint>
- template <class... Ts>
- class type_list
- {
- private:
- template <class U, class V, class... Vs>
- struct type_id {
- static constexpr int id() {
- static_assert(sizeof...(Vs) != 0, "type not registered");
- return type_id<U, Vs...>::id();
- }
- };
- template <class U, class... Vs>
- struct type_id<U, U, Vs...> {
- static constexpr int id() {
- return sizeof...(Vs);
- }
- };
- public:
- template <class U>
- static constexpr int id() {
- return type_id<U, Ts...>::id();
- }
- };
- // Register types here
- using Types = type_list<int16_t, uint32_t>;
- struct ElementInfo
- {
- const char* name;
- const int offset;
- const int type;
- };
- constexpr ElementInfo info[] = {
- { "foo", 1, Types::id<uint32_t>() },
- { "bar", 2, Types::id<int16_t>() },
- };
- int main() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement