class A {...}; template class A {...}; '(if any) prohibited in the C ++ 11 standard? I am tr...">

Where is the "template <typename T> class A {...}; template <typename T> class A <int> {...}; '(if any) prohibited in the C ++ 11 standard?

I am trying to better understand the syntax and semantics of patterns by imagining secret constructs. I believe the following syntax is not allowed by the C ++ 11 standard:

template <typename T> class A {...}; // phony "specialization" template <typename T> class A<int> {...}; 

However, I cannot find in the C ++ 11 standard where this syntax is forbidden.

Is it correct that the given syntax is forbidden by the C ++ 11 standard? If so, where can I find that the syntax is forbidden?

+5
source share
1 answer

I am very surprised that in 14.5.5 [temp.class.spec] there is no explicit statement saying that all the template specialization template parameters should be used in the argument template list. This would invalidate template<class T> class A<int> because T not used in the list of argument templates <int> .

I think that your fake specialization is only implicitly invalid due to the fact that you can never match it, so it can never be used. If you create an instance of A<int> that matches the main template. It cannot correspond to your specialization, because it has an additional template parameter T , which cannot be displayed (you assume that it could be provided by saying A<int><double> , but this is invalid C ++ syntax, therefore does not help).

I asked the standardization committee to clarify why your fake specialization is not valid (obviously this is so, but I can't figure out where it says).

+3
source

Source: https://habr.com/ru/post/1209189/


All Articles