2

Here we go, I got a template class with variadic classes arguments, each class has its own id from an enum value, for example:

struct A
    {
        enum ETypeID
        { 
            Value = 244
        };
    };

(same pattern for some other classes)

now I got :

template<typename TypeList...>
struct TClass
{
    static int _IDs[sizeof(TypeList)...];
};

I can't figure out how to feed the static array with each ETypeID::Value from the given typelist.

Any help would greatly be appreciated

1 Answer 1

3
template<typename... TypeList>
struct TClass
{
    constexpr static int _IDs[sizeof...(TypeList)] = {TypeList::Value...};
};

live example on wandbox


  • constexpr is required for in-place static data member initialization

  • sizeof...(TypeList) evaluates to the number of elements in the TypeList... pack

  • For TypeList = {A, B, C}, TypeList::Value... expands to: A::Value, B::Value, C::Value

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.