【问题标题】:templated template parameter list with template types具有模板类型的模板化模板参数列表
【发布时间】:2011-07-26 17:37:47
【问题描述】:

C++ 允许这样的模板化模板参数:

template <template <bool> class T>
struct something1 {};

Bool 类型可以替换为 typedef(因此不需要原始类型名称出现在声明中):

typedef bool bool_t;
template <template <bool_t> class T>
struct something2 {};

这很好用,但是如果我尝试像这样定义嵌套的 结构

template <typename Type>
struct enclosing
{
   typedef bool bool_t;
   typedef Type type_t; 

   template <template <bool_t> class T>
   struct something3 {};

   template <template <type_t> class T>
   struct something4 {};
};

那么下面的代码编译失败:

template <bool Value>
struct param {};

typedef something1<param> x1; // ok
typedef something2<param> x2; // ok
typedef enclosing<bool>::something3<param> x3; // ok
typedef enclosing<bool>::something4<param> x4; // error

这是符合标准的行为,还是我做错了什么?我正在使用 MSVS 2008。

编辑:
我在 Microsoft 支持论坛上发布了错误报告: Bug Report

【问题讨论】:

  • 对于它的价值,Comeau 编译它没有问题。你的代码对我来说似乎很好,我认为这是一个 VC++ 错误。
  • 代码看起来格式正确。 VC 在某些情况下确实难以处理模板模板参数

标签: c++ templates metaprogramming template-meta-programming


【解决方案1】:

这似乎是 VC++ 中的一个错误;我验证了 VC++ 2010 SP1 中的行为没有改变。我建议在 MS Connect 上发布错误报告,然后在此处发布链接,以便我们投票。

【讨论】:

  • 那很不幸:-(,我会发布一个错误报告,希望他们能在未来的版本中解决这个问题。谢谢你的回答。
猜你喜欢
  • 2018-06-25
  • 1970-01-01
  • 2014-09-16
  • 1970-01-01
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多