Why isn't this valid C++?
template <typename Container, typename T>
bool
foo (const Container <T> &);
g++ gives me Container is not a template
which is clearly not what it really means.
Trying template <typename Container> template <typename T>
doesn't work either, neither does const typename Container <T> &
It seems reasonable to me that one would want to define an interface which is generic over both the container and the contained type.
So,
You can do this:
template <template <class... > class Container, class T>
bool foo (const Container<T> &);
This syntax (class...
) tells the compiler that container
is a template with any number of arguments.
Remember, when you have template <class T>
you want T to be the type. std::vector
is not a type, it is a template. std::vector<int>
is a type, but that is not a template, so you can't have std::vector<int> <char>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With