开发者

Why the template with default template arguments can't be used as template with less template argument in Template Template Parameters

myTemplateTemplate expects the 开发者_如何学Gosecond template parameter is a template with one argument. myDefaultTemplate is a template with two arguments, and the second argument has default type int.

In VS2008, I get the compile error:the template parameter list for class template 'myDefaultTemplate' does not match the template parameter list for template parameter 'TT'

So,why the myDefaultTemplate can't be used as the template with just one argument? Are there any negative impact if C++ compiler supports it?

template
<typename T1, typename T2 = int>
class
myDefaultTemplate{
      T1 a;
      T2 b;
};

template
<typename T1, template<typename T2> class TT>
class
myTemplateTemplate{
      T1 a;
      TT<T1> b;
};

int main(int argc, char* argv[]){
      myTemplateTemplate<int, myDefaultTemplate> bar; //error here:      
      return 0;
}


From the standard (see 14.3.3 paragraph 1 - [temp.arg.template):

A template-argument for a template template-parameter shall be the name of a class template, expressed as id-expression. Only primary class templates are considered when matching the template template argument with the corresponding parameter; partial specializations are not considered even if their parameter lists match that of the template template parameter.

That means the template myDefaultTemplate will be seen only as 2 arguments template. The default argument will not be considered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜