As an exercise, I'm trying to define a variadic template for a Tuple but I found that the base case with no elements is not working.
template <typename Head, typename... Tail>
struct Tuple : Tuple<Tail...>
{
Tuple(const Head& head, const Tail&... tail)
: Base{tail...}, m_head{head} {}
private:
using Base = Tuple<Tail...>;
Head m_head;
};
template <> struct Tuple<> {};
MSVC 2022 gives the following error:
C:\projects\cpp\cpp_programming_language\28_metaprogramming\variadic_tuple.cpp(12): error C2976: 'Tuple': too few template arguments
C:\projects\cpp\cpp_programming_language\28_metaprogramming\variadic_tuple.cpp(2): note: see declaration of 'Tuple'
C:\projects\cpp\cpp_programming_language\28_metaprogramming\variadic_tuple.cpp(12): error C2913: explicit specialization; 'Tuple' is not a specialization of a class template
Why this does not work and how to fix it?
Aucun commentaire:
Enregistrer un commentaire