Explicit specialization of C ++ member template belonging to the template class

In the current standard C ++ draft, there is this example in this paragraph relating to the section related to the explicit specialization of templates:

template<class T> struct A {
   void f(T);
   template<class X1> void g1(T, X1);
   template<class X2> void g2(T, X2);
   void h(T) { }
};

// specialization
template<> void A<int>::f(int);

// out of class member template definition
template<class T> template<class X1> void A<T>::g1(T, X1) { }


// member template specialization
template<> template<class X1> void A<int>::g1(int, X1);  //(1)

// member template specialization
template<> template<>
void A<int>::g1(int, char);                              //(2)

In (1), it seems that he g1specialized as still a function template in the specialized version of A (A <int>), and in (2) it seems that g1he specialized in his own template set parameters ((int, from A <int>) , char).

, ( , (1) g1 " " "" A, (2 ) g1 ( ).

, :

template<class T> struct A{
   int f() { return 1; }
}

template<>
int A<int>::f() { return 2; }                            //(3)

(1) (3) "", "", (2) ().

?

.

+4
1

-, # 3 , , f , , , , .

, # 1 A<T>, T int - A<int>, . , , (). , .

, # 2 , A<int> - A<int>::g1, "A<T>::g1, T int" №1. , , , , # 3. ( # 2 , # 1!)

[temp.expl.spec]/15 , . : .

+1

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


All Articles