c – 是否允许模板模板参数接收从先前参数解析的参数?
我在g 4.4和4.5上发现了一个奇怪的问题.我问过这个因为我认为我在代码中犯了一些愚蠢的错误.原帖是
here,但是对于后期的完整性,我会在这里重新发布有问题的代码:
$cat templatetemplate.cc template <int i> struct LabelTypeMap { typedef int type_t; }; template <bool> struct Hold { typedef int type; }; template<typename Holder,template<typename Holder::type> class typeMap> struct Whatever { }; template <bool Enable> struct Now { typedef Whatever<Hold<ENABLE>,LabelTypeMap> concrete_t; }; Now<true>::concrete_t obj; $g++ -DENABLE=Enable -c templatetemplate.cc templatetemplate.cc:11: error: type/value mismatch at argument 2 in template parameter list for ‘template<class Holder,template<typename Holder::type <anonymous> > class typeMap> struct Whatever’ templatetemplate.cc:11: error: expected a template of type ? ‘template<typename Holder::type <anonymous> > class typeMap’,got ? ‘template<int i> struct LabelTypeMap’ marcelo@macbookpro-1:~/play$ $g++ -DENABLE=true -c templatetemplate.cc (no error) 它似乎不是真正的程序员错误,虽然它可能有可能我错过了模板模板参数解析的一些模糊规则.然而,我尝试将错误发布到ubuntu跟踪器(希望他们会解雇它或以其他方式向上游发送错误) 所以,只是为了检查这是否真的是一个错误,我得到了2003年标准的副本,我现在已经阅读了第14.3.3节,但我仍觉得如果路过,我会错过最轻微的线索允许或禁止带有参数的模板模板参数,如示例代码中所示.我甚至不确定文件的这一部分是否提到了这一点 这是我的问题:你知道这是指定的吗? 编辑:非常有趣的是,这个问题现在已经有一个多星期无法回答:它让我相信ISO c标准没有指定我们是否可以使用以前的模板参数来指定后续模板参数的类型(至少在陈述的形式),基本上由实施者决定 第二次编辑(2011年10月1日):人们,可能有一些事情我们都缺少(或者许多高技能的编译器设计者都错了): $icpc ttemplatetemplate.cc -o ./x2test templatetemplate.cc(12): error: class template "LabelTypeMap" is not compatible with template template parameter "typeMap" struct Now { typedef Whatever<Hold<Enable>,LabelTypeMap> concrete_t; }; ^ compilation aborted for templatetemplate.cc (code 2) $icpc --version icpc (ICC) 12.0.0 20101116 Copyright (C) 1985-2010 Intel Corporation. All rights reserved. 解决方法
我在标准中找不到禁止它的任何内容,虽然我在
Comeau中尝试了这个简单的代码(在我看来这是对问题的简化):
template<int> class A {}; template<class T,template<T> class U> class B {}; B<int,A> b; 它会产生以下错误:
我希望我能找到标准的哪一部分实际上禁止它…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |