Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specialization that is itself a template

I have a template class that I have some specializations for.
But the next specialization is a template itself. How do you specify this:

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";}
}
like image 807
Martin York Avatar asked Jan 16 '12 07:01

Martin York


1 Answers

Trivial partial specialization ?

template <typename T>
class Action<std::vector<T>> {
public:
  void doStuff() { std::cout << "A Generic Vector\n"; }
};
like image 76
Matthieu M. Avatar answered Oct 21 '22 03:10

Matthieu M.