Specializing a variadic template template parameter on the minimum number of arguments: legal or not?

后端 未结 2 891
傲寒
傲寒 2021-02-19 02:39

I have code:

#include 

template class>
struct Foo 
{ 
    enum { n = 77 };
};

template

        
2条回答
  •  别跟我提以往
    2021-02-19 03:37

    `template class C> 
    

    is no more specialized than

    template class>
    

    Both of them takes a list of unknown type parameters. it is just that the former takes one member of this list as a different parameter. It contains no additional info about the type such that the compiler should select one over the other.

    In the typical usage of variadic templates this specialization is generated in terms of parameter count. Thinking about the variadic templates as recursive functions during runtime, you should just supply the terminating condition (as a class taking only one unknown type).

    Clang is very keen on diagnostics so I think it is catching the abnormality and rightfully giving errors. GCC's being able to compile it is strange. Maybe because you are explicitly specifying which templates to use in struct A and struct B seperately, gcc was able to catch that and suppress the abnormality.

提交回复
热议问题