[35.22] Follow-up to previous: can I pass in the underlying structure and the element-type separately?
Yes, with a "proxy" trick.
Here's the problem: std::vector template can have, does have, more
than one argument. You're required to make them match in the number, order,
and nature — type/non-type, etc.
It is possible, however, to "cheat" your way out of specifying all those
arguments and use the defaults. It's called the "proxy template" technique:
#include <vector>
#include <list>
template<typename T>
struct wrap_vector {
typedef std::vector<T> type;
};
template<typename T>
struct wrap_list {
typedef std::list<T> type;
};
template<typename T, template<typename> class C>
struct A {
typename C<T>::type data; // trick to use a proxy
};
int main()
{
A<int,wrap_vector> avi;
A<double,wrap_list> adl;
...
}
You can also create a proxy if you actually have a template that takes only
one argument:
template<typename T>
struct wrap_my1argtemplate {
typedef my1argtemplate<T> type;
};
The "template typedefs" proposal will allow redefining templates just like we
do with types, which will make the proxy-trick unnecessary. Until then, use
something like the above.