Why doesn’t this work?
template <typename T, typename U>
class TSContainer {
private:
U<T> container;
};
called as:
TSContainer<int, std::vector> ts;
I think a solution might be:
template <typename T, template <typename> typename C>
class TSContainer
{
C<T> container;
};
but that doesn’t work either.
This is what you need:
Note that
std::vectortakes two template parameters with the second being defaulted tostd::allocator. Alternatively, you can write:Both of these force the selection of the allocator on you. If you want to control which allocator is used by your vector (i.e. what is used as second template parameter to
C), you can also use this:This is the most flexible solution.