C++11 将非专用模板传递给另一个模板

C++11 将非专用模板传递给另一个模板,c++11,templates,C++11,Templates,给定以下代码: 我得到一个错误: prog.cpp:20:24: error: ‘C’ is not a template using collection = C<T>; ^ prog.cpp: In function ‘int main()’: prog.cpp:27:43: error: type/value mismatch at argument 1 in template parameter list for ‘t

给定以下代码:

我得到一个错误:

prog.cpp:20:24: error: ‘C’ is not a template
     using collection = C<T>;
                        ^
prog.cpp: In function ‘int main()’:
prog.cpp:27:43: error: type/value mismatch at argument 1 in template parameter list for ‘template<class C, class T> class MyMoreGenericCollection’
     MyMoreGenericCollection<std::list, int> c;
                                           ^
prog.cpp:27:43: note:   expected a type, got ‘list’
我如何编写代码,以便在编译时使用C语言,而不必明确列出潜在的专业化,并且尽可能避免使用宏?我意识到std::list不是一个类型名,但我不知道如何进行,我一直无法在这里找到类似的问题


请注意,这只是一个MCVE,我的实际使用要复杂得多。

为了整理一下,这里是解决方案。我寻找的搜索词是模板,虽然我确实找到了一个可能的副本,但我认为这个问题和答案更容易理解

所以,多亏了@Some programmer dude的提示,我查了一下,它确实可以编译:

template<template<typename, typename> class C, typename T>
class MyMoreGenericCollection
{
    using collection = C<T, std::allocator<T>>;
};
我们将第一个模板参数声明为模板本身,记住标准库构造函数采用两个参数,我们需要使内部模板采用两个参数。据我所知,没有办法自动使用默认的第二个参数,因此为了这个示例,我显式地声明了默认值


当然,我可以向主模板添加第三个参数,用于指定分配器,分配器本身也是一个模板,但我将此作为练习留给读者。

MyGenericCollection不需要t template参数。至于您的问题,您需要对模板做一些研究。你需要在模板参数列表中将C作为模板。@Someprogrammerdude啊,我发现了一个可能的副本!这似乎是问题的答案。
template<template<typename, typename> class C, typename T>
class MyMoreGenericCollection
{
    using collection = C<T, std::allocator<T>>;
};