【问题标题】:Partially default initialize template template parameters with internal type部分默认使用内部类型初始化模板模板参数
【发布时间】:2013-09-09 05:06:20
【问题描述】:
template <template <typename> class container_type>
class MyClass
{
    class Internal{
    };
};

我想以如下方式使用这个类(或它的正确外观)......

MyClass(std::list);

...所以在 MyClass 中 container_type 被声明为/typedef'd 为:

std::list<Internal*>

这样的事情有可能吗?

【问题讨论】:

  • 你对 Stroustrup 缩进风格有什么看法...?
  • 很难在视觉上匹配左大括号
  • @greatwolf 你一般不会根据编程风格进行编辑。

标签: c++ templates c++11 template-templates


【解决方案1】:

您可能想要以下内容:

#include <list>
#include <memory>

template <template <typename, typename> 
          class Container = std::list>
class MyClass 
{
    class Internal
    { };

    Container<Internal*, std::allocator<Internal*>> my_list;
};

int main()
{
    MyClass<> m;
}

Here's 一个你可以玩的可编译的例子。请注意,此处需要额外的typename 和分配器的定义。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
  • 2012-08-29
  • 1970-01-01
相关资源
最近更新 更多