Yes, but not directly:
template <typename Item, template <typename> class Container>
struct TList
{
typedef typename Container<Item>::type type;
};
Then you can define various container policies:
template <typename T>
struct vector_container
{
typedef std::vector<T> type;
};
template <typename T>
struct map_container
{
typedef std::map<T, std::string> type;
};
TList<int, vector_container> v;
TList<int, map_container> m;
A bit detailed. * To do something directly, you need to take the route described by James , but since he notes that it is ultimately very inflexible.
++ 0x :
#include <map>
#include <vector>
template <typename Item,
template <typename...> class Container, typename... Args>
struct TList
{
Container<Item, Args...> storage;
};
int main()
{
TList<int, std::vector> v;
TList<int, std::map, float> m;
}
Perfect. , ++ 03, , .
* , " " " ". - , , . :
template <typename Item, typename Container = std::vector<Item>>
struct TList
{};
: , , Item, something_else<Item>? , - ? , , , , .
, , :
template <typename T>
struct allocator
{
template <typename U>
struct rebind
{
typedef allocator<U> type;
};
};
allocator<U> allocator<T>. ? ++ 0x :
template <typename T, typename Container>
struct rebind;
template <typename T, typename Container, typename... Args>
struct rebind<T, Container<Args...>>
{
typedef Container<T> type;
};
std::vector<int>, , , rebind<float, std::vector<int>>::type. ++ 0x, ++ 03 .
** , , , , , , .., .:)