tmp/tmp5u3ovenm/{from.md → to.md}
RENAMED
|
@@ -6,29 +6,35 @@ within or outside its class definition or class template definition. A
|
|
| 6 |
member template of a class template that is defined outside of its class
|
| 7 |
template definition shall be specified with the *template-parameter*s of
|
| 8 |
the class template followed by the *template-parameter*s of the member
|
| 9 |
template.
|
| 10 |
|
|
|
|
|
|
|
| 11 |
``` cpp
|
| 12 |
template<class T> struct string {
|
| 13 |
template<class T2> int compare(const T2&);
|
| 14 |
-
template<class T2> string(const string<T2>& s) {
|
| 15 |
};
|
| 16 |
|
| 17 |
template<class T> template<class T2> int string<T>::compare(const T2& s) {
|
| 18 |
}
|
| 19 |
```
|
| 20 |
|
|
|
|
|
|
|
| 21 |
A local class of non-closure type shall not have member templates.
|
| 22 |
Access control rules (Clause [[class.access]]) apply to member template
|
| 23 |
names. A destructor shall not be a member template. A non-template
|
| 24 |
member function ([[dcl.fct]]) with a given name and type and a member
|
| 25 |
function template of the same name, which could be used to generate a
|
| 26 |
specialization of the same type, can both be declared in a class. When
|
| 27 |
both exist, a use of that name and type refers to the non-template
|
| 28 |
member unless an explicit template argument list is supplied.
|
| 29 |
|
|
|
|
|
|
|
| 30 |
``` cpp
|
| 31 |
template <class T> struct A {
|
| 32 |
void f(int);
|
| 33 |
template <class T2> void f(T2);
|
| 34 |
};
|
|
@@ -42,38 +48,49 @@ int main() {
|
|
| 42 |
ac.f('c'); // template
|
| 43 |
ac.f<>(1); // template
|
| 44 |
}
|
| 45 |
```
|
| 46 |
|
|
|
|
|
|
|
| 47 |
A member function template shall not be virtual.
|
| 48 |
|
|
|
|
|
|
|
| 49 |
``` cpp
|
| 50 |
template <class T> struct AA {
|
| 51 |
template <class C> virtual void g(C); // error
|
| 52 |
virtual void f(); // OK
|
| 53 |
};
|
| 54 |
```
|
| 55 |
|
|
|
|
|
|
|
| 56 |
A specialization of a member function template does not override a
|
| 57 |
virtual function from a base class.
|
| 58 |
|
|
|
|
|
|
|
| 59 |
``` cpp
|
| 60 |
class B {
|
| 61 |
virtual void f(int);
|
| 62 |
};
|
| 63 |
|
| 64 |
class D : public B {
|
| 65 |
template <class T> void f(T); // does not override B::f(int)
|
| 66 |
-
void f(int i) { f<>(i); } // overriding function that calls
|
| 67 |
-
// the template instantiation
|
| 68 |
};
|
| 69 |
```
|
| 70 |
|
|
|
|
|
|
|
| 71 |
A specialization of a conversion function template is referenced in the
|
| 72 |
same way as a non-template conversion function that converts to the same
|
| 73 |
type.
|
| 74 |
|
|
|
|
|
|
|
| 75 |
``` cpp
|
| 76 |
struct A {
|
| 77 |
template <class T> operator T*();
|
| 78 |
};
|
| 79 |
template <class T> A::operator T*(){ return 0; }
|
|
@@ -81,20 +98,21 @@ template <> A::operator char*(){ return 0; } // specialization
|
|
| 81 |
template A::operator void*(); // explicit instantiation
|
| 82 |
|
| 83 |
int main() {
|
| 84 |
A a;
|
| 85 |
int* ip;
|
| 86 |
-
ip = a.operator int*(); // explicit call to template operator
|
| 87 |
-
// A::operator int*()
|
| 88 |
}
|
| 89 |
```
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
function name, there is no way to provide an explicit template argument
|
| 95 |
-
list for these function templates.
|
| 96 |
|
| 97 |
A specialization of a conversion function template is not found by name
|
| 98 |
lookup. Instead, any conversion function templates visible in the
|
| 99 |
context of the use are considered. For each such operator, if argument
|
| 100 |
deduction succeeds ([[temp.deduct.conv]]), the resulting specialization
|
|
|
|
| 6 |
member template of a class template that is defined outside of its class
|
| 7 |
template definition shall be specified with the *template-parameter*s of
|
| 8 |
the class template followed by the *template-parameter*s of the member
|
| 9 |
template.
|
| 10 |
|
| 11 |
+
[*Example 1*:
|
| 12 |
+
|
| 13 |
``` cpp
|
| 14 |
template<class T> struct string {
|
| 15 |
template<class T2> int compare(const T2&);
|
| 16 |
+
template<class T2> string(const string<T2>& s) { ... }
|
| 17 |
};
|
| 18 |
|
| 19 |
template<class T> template<class T2> int string<T>::compare(const T2& s) {
|
| 20 |
}
|
| 21 |
```
|
| 22 |
|
| 23 |
+
— *end example*]
|
| 24 |
+
|
| 25 |
A local class of non-closure type shall not have member templates.
|
| 26 |
Access control rules (Clause [[class.access]]) apply to member template
|
| 27 |
names. A destructor shall not be a member template. A non-template
|
| 28 |
member function ([[dcl.fct]]) with a given name and type and a member
|
| 29 |
function template of the same name, which could be used to generate a
|
| 30 |
specialization of the same type, can both be declared in a class. When
|
| 31 |
both exist, a use of that name and type refers to the non-template
|
| 32 |
member unless an explicit template argument list is supplied.
|
| 33 |
|
| 34 |
+
[*Example 2*:
|
| 35 |
+
|
| 36 |
``` cpp
|
| 37 |
template <class T> struct A {
|
| 38 |
void f(int);
|
| 39 |
template <class T2> void f(T2);
|
| 40 |
};
|
|
|
|
| 48 |
ac.f('c'); // template
|
| 49 |
ac.f<>(1); // template
|
| 50 |
}
|
| 51 |
```
|
| 52 |
|
| 53 |
+
— *end example*]
|
| 54 |
+
|
| 55 |
A member function template shall not be virtual.
|
| 56 |
|
| 57 |
+
[*Example 3*:
|
| 58 |
+
|
| 59 |
``` cpp
|
| 60 |
template <class T> struct AA {
|
| 61 |
template <class C> virtual void g(C); // error
|
| 62 |
virtual void f(); // OK
|
| 63 |
};
|
| 64 |
```
|
| 65 |
|
| 66 |
+
— *end example*]
|
| 67 |
+
|
| 68 |
A specialization of a member function template does not override a
|
| 69 |
virtual function from a base class.
|
| 70 |
|
| 71 |
+
[*Example 4*:
|
| 72 |
+
|
| 73 |
``` cpp
|
| 74 |
class B {
|
| 75 |
virtual void f(int);
|
| 76 |
};
|
| 77 |
|
| 78 |
class D : public B {
|
| 79 |
template <class T> void f(T); // does not override B::f(int)
|
| 80 |
+
void f(int i) { f<>(i); } // overriding function that calls the template instantiation
|
|
|
|
| 81 |
};
|
| 82 |
```
|
| 83 |
|
| 84 |
+
— *end example*]
|
| 85 |
+
|
| 86 |
A specialization of a conversion function template is referenced in the
|
| 87 |
same way as a non-template conversion function that converts to the same
|
| 88 |
type.
|
| 89 |
|
| 90 |
+
[*Example 5*:
|
| 91 |
+
|
| 92 |
``` cpp
|
| 93 |
struct A {
|
| 94 |
template <class T> operator T*();
|
| 95 |
};
|
| 96 |
template <class T> A::operator T*(){ return 0; }
|
|
|
|
| 98 |
template A::operator void*(); // explicit instantiation
|
| 99 |
|
| 100 |
int main() {
|
| 101 |
A a;
|
| 102 |
int* ip;
|
| 103 |
+
ip = a.operator int*(); // explicit call to template operator A::operator int*()
|
|
|
|
| 104 |
}
|
| 105 |
```
|
| 106 |
|
| 107 |
+
— *end example*]
|
| 108 |
+
|
| 109 |
+
[*Note 1*: Because the explicit template argument list follows the
|
| 110 |
+
function template name, and because conversion member function templates
|
| 111 |
+
and constructor member function templates are called without using a
|
| 112 |
function name, there is no way to provide an explicit template argument
|
| 113 |
+
list for these function templates. — *end note*]
|
| 114 |
|
| 115 |
A specialization of a conversion function template is not found by name
|
| 116 |
lookup. Instead, any conversion function templates visible in the
|
| 117 |
context of the use are considered. For each such operator, if argument
|
| 118 |
deduction succeeds ([[temp.deduct.conv]]), the resulting specialization
|