Okay, simple template question. Say I define my template class something like this:
template
class foo {
public:
foo(T const& first
Make the template templated on a template template parameter:
template class Container>
void bar(const Container & c, const T & t)
{
//
}
If you don't have C++11, then you can't use variadic templates, and you have to provide as many template parameters as your container takes. For example, for a sequence container you might need two:
template class Container, typename Alloc>
void bar(const Container & c, const T & t);
Or, if you only want to allow allocators which are themselves template instances:
template class Container, template class Alloc>
void bar(const Container > & c, const T & t);
As I suggested in the comments, I would personally prefer to make the entire container a templated type and use traits to check if it's valid. Something like this:
template
typename std::enable_if::value, void>::type
bar(const Container & c, const T & t);
This is more flexible since the container can now be anything that exposes the value_type
member type. More sophisticated traits for checking for member functions and iterators can be conceived of; for example, the pretty printer implements a few of those.