How to specialize a class template for vector?

826 views Asked by At

I am a bit confused about the syntax for template parameters... How do i specalize this template:

template <typename T> class MyTemplate{
    public: 
        void doSomething(T){}
};

for std::vectors, i.e. I would to write something like

template <std::vector<typename T> > class MyTemplate{
    public:
        void doSomethingElse(std::vector<T>){}
};

to make the class behave differently, depending on whether the template parameter is just any type T or a vector.

1

There are 1 answers

1
Barry On BEST ANSWER

Like this:

template <typename T>
class MyTemplate<std::vector<T> > {
    ...
};