mercredi 3 juillet 2019

Why do we need a template specialization for a template-template parameter

Take as an example this code to determine the length of a type list:

template <class... Types>
class type_list {};

template <class TypeList>
struct type_list_length;  // <---

template <template <class...> class type_list, class... Types>
struct type_list_length<TypeList<Types...>>
{
    static constexpr std::size_t value = sizeof...(Types);
};

Godbolt

Why do we need the marked declaration? I tried to compile the code without it in several compilers but are always getting errors.

Aucun commentaire:

Enregistrer un commentaire