3

This example code generates expected a class template, got std::pair <_T1, _T2>. I tried using struct Struct <std::pair> {};, but then parameters T and M become undeducible. How to avoid this?

    template <template <class...> class>
    struct Struct {};

    template <class T, class M>
    struct Struct <std::pair <T, M>> {};
Alex
  • 1,165
  • 2
  • 9
  • 27
  • 2
    `std::pair` is class template, `std::pair <_T1, _T2>` is not. You might change the primary template declaration to `template struct Struct {};`. – songyuanyao Jul 25 '16 at 08:21

2 Answers2

4

Depending of what you want

template <template <class...> class>
struct Struct {};

template <>
struct Struct <std::pair>
{
    // Specialization
};

or

template <typename> struct Struct {};

template <typename First, typename Second>
struct Struct <std::pair<First, Second>>
{
    // Specialization
};
Jarod42
  • 203,559
  • 14
  • 181
  • 302
2

That is not a valid specialization for your template.

The reason why is because std::pair<T, M> is a full specialization of the class template std::pair and therefore a class. Your template expects a class template parameter which is exactly what the compiler is telling you.

Rerito
  • 5,886
  • 21
  • 47