Using a template name instead of defining an identifier template inside a class

Is the following C ++ code correct? And if so, can someone point me to a clause in the standard that mentions this? It seems that you can use the template name instead of the template identifier in the area enclosed in the template, and the compiler automatically adds a list of template arguments.

template<class Type> class Mana { public: Mana(const Mana& m) {/*...*/} Mana() {/*...*/} }; 

Unlike:

 template<class Type> class Mana { public: Mana(const Mana<Type>& m) {/*...*/} Mana() {/*...*/} }; 

The code compiles with g ++, as well as in the MS visual studio.

+6
source share
1 answer

Yes, the code is correct. (Quote: Β§14.6.1 [temp.local] / 2

Within the scope of a class template specialization or partial specialization, when the name of the introduced class is used as the type name, it is equivalent to the template name, followed by the template arguments of the class, template specialization or partial specialization enclosed in <> . [Example:

 template<template<class> class T> class A { }; template<class T> class Y; template<> class Y<int> { Y* p; // meaning Y<int> Y<char>* q; // meaning Y<char> A<Y>* a; // meaning A<::Y> class B { template<class> friend class Y; // meaning ::Y }; }; 

- end of example]

)

In fact, it is used throughout the standard, for example,

 // Β§20.4.2.1[tuple.cnstr]/10-13 tuple(const tuple& u) = default; tuple(tuple&& u) = default; // Β§21.4.6.1[string::op+=]/1-2 basic_string& operator+=(const basic_string& str); // etc. 
+7
source

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


All Articles