【发布时间】: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