C++ 默认值未知的模板参数

C++ 默认值未知的模板参数,c++,templates,C++,Templates,我有一个模板函数,它将容器作为参数 (我对vector、set和map都使用此函数,因此尝试避免此操作将花费大量代码复制) 因此,我自然宣布: template<template<class T, class Allocator = std::allocator<T>> class Container> Container<std::weak_ptr<A>>* Foo() {...} 在这种情况下,分配器的默认值与Foo-std::

我有一个模板函数,它将容器作为参数 (我对vector、set和map都使用此函数,因此尝试避免此操作将花费大量代码复制) 因此,我自然宣布:

template<template<class T, class Allocator = std::allocator<T>> class 
Container> Container<std::weak_ptr<A>>* Foo() {...}
在这种情况下,分配器的默认值与
Foo
-
std::allocator
std::allocator
定义中的值不同

长话短说,我需要将它发送到
Foo
一个容器,其中包含第二个参数,可以在不知道默认类型的情况下进行默认设置(因此此函数模板可以用于map、vector或基本上任何其他容器)。这可能吗


编辑:我不能以任何方式使用C++11,编译器是gcc 4.1.2(我无法控制)

在C++11中,您可以使用任何模板作为模板参数:

template<template <class ...> class Container>
Container<std::weak_ptr<A>>* Foo() {...}
模板
容器*Foo(){…}

这里有一个关于模板参数如何操作的误解。本声明:

template<template<class T, class Allocator = std::allocator<T>> class Container> 
Container<std::weak_ptr<A>>* Foo() {...}
template < template <class, class> class Container> 
Container<std::weak_ptr<A>>* Foo() {...}
它不适用于,因为它接受四个模板类型参数:

template<
    class T,
    class Allocator = std::allocator<T>
> class vector;
template<
    class Key,
    class T,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<std::pair<const Key, T> >
> class map;
template < template <class...> class Container> 
Container<std::weak_ptr<A>>* Foo() {...}
模板<
类密钥,
T类,
类比较=标准::更少,
类分配器=std::分配器
>类图;
在C++11中,可以对函数进行泛化,使模板参数接受任意数量的模板类型参数:

template<
    class T,
    class Allocator = std::allocator<T>
> class vector;
template<
    class Key,
    class T,
    class Compare = std::less<Key>,
    class Allocator = std::allocator<std::pair<const Key, T> >
> class map;
template < template <class...> class Container> 
Container<std::weak_ptr<A>>* Foo() {...}
template