463035818_is_not_an_ai
463035818_is_not_an_ai

Reputation: 122228

How to specialize a class template for vector?

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.

Upvotes: 1

Views: 834

Answers (1)

Barry
Barry

Reputation: 302807

Like this:

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

Upvotes: 3

Related Questions