Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to templatize the container type in a function declaration?

Tags:

c++

templates

I want to write a function that accepts any container holding strings. Something like this:

template <typename Container> void foo(Container<string>& stuff);

But this isn't the right syntax. What's the right syntax?

like image 894
Kyle Avatar asked May 10 '26 23:05

Kyle


1 Answers

You need a template template parameter:

template < template <typename> class Container> void foo (Container<string>& stuff);
like image 166
MSN Avatar answered May 12 '26 13:05

MSN