How to declare a template template

Suppose I have two classes Foo1<T> and Foo2<T> .

Then I want to create a bar function that references std::vector<Foo1<T>> or std::vector<Foo2<T>> , but always returns a std::vector<Foo1<T>> :

template<class T, class Y> std::vector<Foo1<T>> bar(std::vector<Y<T>>&)

Unfortunately, the compiler does not like the bit <Y<T>> . One way around this is to provide two overloads, but is there a way I can arrange above to fix it?

+7
c ++ c ++ 11 templates
source share
1 answer

You need a template template :

 template<class T, template <typename> class Y> std::vector<Foo1<T>> bar(std::vector<Y<T>>&) {} 
+17
source share

All Articles