Подтвердить что ты не робот

Специализация, которая сама по себе является шаблоном

У меня есть класс шаблона, для которого у меня есть некоторые специализации. Но следующая специализация - это сам шаблон. Как вы это указываете:

template<typename T>
class Action
{
    public: void doStuff()  { std::cout << "Generic\n"; }
}

// A specialization for a person
template<>
class Action<Person>
{
    public: void doStuff()  { std::cout << "A Person\n";}
}


// I can easily specialize for vectors of a particular type.
// But how  do I change the following so that it works with all types of vector.
// Not just `int`
template<>
class Action<std::vector<int> >
{
    public: void doStuff()  { std::cout << "A Generic Vector\n";}
}
4b9b3361

Ответ 1

Тривиальная частичная специализация?

template <typename T>
class Action<std::vector<T>> {
public:
  void doStuff() { std::cout << "A Generic Vector\n"; }
};