From Jason Turner

[temp.arg.explicit]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_3u1cuag/{from.md → to.md} +31 -63
tmp/tmp_3u1cuag/{from.md → to.md} RENAMED
@@ -1,11 +1,12 @@
1
  ### Explicit template argument specification <a id="temp.arg.explicit">[[temp.arg.explicit]]</a>
2
 
3
  Template arguments can be specified when referring to a function
4
- template specialization by qualifying the function template name with
5
- the list of *template-argument*s in the same way as *template-argument*s
6
- are specified in uses of a class template specialization.
 
7
 
8
  [*Example 1*:
9
 
10
  ``` cpp
11
  template<class T> void sort(Array<T>& v);
@@ -26,24 +27,28 @@ void g(double d) {
26
  }
27
  ```
28
 
29
  — *end example*]
30
 
 
 
 
 
31
  A template argument list may be specified when referring to a
32
  specialization of a function template
33
 
34
  - when a function is called,
35
  - when the address of a function is taken, when a function initializes a
36
  reference to function, or when a pointer to member function is formed,
37
  - in an explicit specialization,
38
  - in an explicit instantiation, or
39
  - in a friend declaration.
40
 
41
- Trailing template arguments that can be deduced ([[temp.deduct]]) or
42
  obtained from default *template-argument*s may be omitted from the list
43
- of explicit *template-argument*s. A trailing template parameter pack (
44
- [[temp.variadic]]) not otherwise deduced will be deduced to an empty
45
  sequence of template arguments. If all of the template arguments can be
46
  deduced, they may all be omitted; in this case, the empty template
47
  argument list `<>` itself may also be omitted. In contexts where
48
  deduction is done and fails, or in contexts where deduction is not done,
49
  if a template argument list is specified and it, along with any default
@@ -55,27 +60,27 @@ template specialization.
55
 
56
  ``` cpp
57
  template<class X, class Y> X f(Y);
58
  template<class X, class Y, class ... Z> X g(Y);
59
  void h() {
60
- int i = f<int>(5.6); // Y is deduced to be double
61
- int j = f(5.6); // ill-formed: X cannot be deduced
62
- f<void>(f<int, bool>); // Y for outer f deduced to be int (*)(bool)
63
- f<void>(f<int>); // ill-formed: f<int> does not denote a single function template specialization
64
- int k = g<int>(5.6); // Y is deduced to be double, Z is deduced to an empty sequence
65
- f<void>(g<int, bool>); // Y for outer f is deduced to be int (*)(bool),
66
- // Z is deduced to an empty sequence
67
  }
68
  ```
69
 
70
  — *end example*]
71
 
72
  [*Note 1*:
73
 
74
  An empty template argument list can be used to indicate that a given use
75
  refers to a specialization of a function template even when a
76
- non-template function ([[dcl.fct]]) is visible that would otherwise be
77
  used. For example:
78
 
79
  ``` cpp
80
  template <class T> int f(T); // #1
81
  int f(int); // #2
@@ -96,23 +101,23 @@ there are corresponding *template-parameter*s unless one of the
96
  ``` cpp
97
  template<class X, class Y, class Z> X f(Y,Z);
98
  template<class ... Args> void f2();
99
  void g() {
100
  f<int,const char*,double>("aa",3.0);
101
- f<int,const char*>("aa",3.0); // Z is deduced to be double
102
- f<int>("aa",3.0); // Y is deduced to be const char*, and Z is deduced to be double
103
  f("aa",3.0); // error: X cannot be deduced
104
  f2<char, short, int, long>(); // OK
105
  }
106
  ```
107
 
108
  — *end example*]
109
 
110
- Implicit conversions (Clause  [[conv]]) will be performed on a function
111
- argument to convert it to the type of the corresponding function
112
- parameter if the parameter type contains no *template-parameter*s that
113
- participate in template argument deduction.
114
 
115
  [*Note 2*:
116
 
117
  Template parameters do not participate in template argument deduction if
118
  they are explicitly specified. For example,
@@ -130,63 +135,26 @@ void g() {
130
  ```
131
 
132
  — *end note*]
133
 
134
  [*Note 3*: Because the explicit template argument list follows the
135
- function template name, and because conversion member function templates
136
- and constructor member function templates are called without using a
137
- function name, there is no way to provide an explicit template argument
138
- list for these function templates. — *end note*]
139
-
140
- [*Note 4*:
141
-
142
- For simple function names, argument dependent lookup (
143
- [[basic.lookup.argdep]]) applies even when the function name is not
144
- visible within the scope of the call. This is because the call still has
145
- the syntactic form of a function call ([[basic.lookup.unqual]]). But
146
- when a function template with explicit template arguments is used, the
147
- call does not have the correct syntactic form unless there is a function
148
- template with that name visible at the point of the call. If no such
149
- name is visible, the call is not syntactically well-formed and
150
- argument-dependent lookup does not apply. If some such name is visible,
151
- argument dependent lookup applies and additional function templates may
152
- be found in other namespaces.
153
-
154
- [*Example 4*:
155
-
156
- ``` cpp
157
- namespace A {
158
- struct B { };
159
- template<int X> void f(B);
160
- }
161
- namespace C {
162
- template<class T> void f(T t);
163
- }
164
- void g(A::B b) {
165
- f<3>(b); // ill-formed: not a function call
166
- A::f<3>(b); // well-formed
167
- C::f<3>(b); // ill-formed; argument dependent lookup applies only to unqualified names
168
- using C::f;
169
- f<3>(b); // well-formed because C::f is visible; then A::f is found by argument dependent lookup
170
- }
171
- ```
172
-
173
- — *end example*]
174
-
175
- — *end note*]
176
 
177
  Template argument deduction can extend the sequence of template
178
  arguments corresponding to a template parameter pack, even when the
179
  sequence contains explicitly specified template arguments.
180
 
181
- [*Example 5*:
182
 
183
  ``` cpp
184
  template<class ... Types> void f(Types ... values);
185
 
186
  void g() {
187
- f<int*, float*>(0, 0, 0); // Types is deduced to the sequence int*, float*, int
188
  }
189
  ```
190
 
191
  — *end example*]
192
 
 
1
  ### Explicit template argument specification <a id="temp.arg.explicit">[[temp.arg.explicit]]</a>
2
 
3
  Template arguments can be specified when referring to a function
4
+ template specialization that is not a specialization of a constructor
5
+ template by qualifying the function template name with the list of
6
+ *template-argument*s in the same way as *template-argument*s are
7
+ specified in uses of a class template specialization.
8
 
9
  [*Example 1*:
10
 
11
  ``` cpp
12
  template<class T> void sort(Array<T>& v);
 
27
  }
28
  ```
29
 
30
  — *end example*]
31
 
32
+ Template arguments shall not be specified when referring to a
33
+ specialization of a constructor template ([[class.ctor]],
34
+ [[class.qual]]).
35
+
36
  A template argument list may be specified when referring to a
37
  specialization of a function template
38
 
39
  - when a function is called,
40
  - when the address of a function is taken, when a function initializes a
41
  reference to function, or when a pointer to member function is formed,
42
  - in an explicit specialization,
43
  - in an explicit instantiation, or
44
  - in a friend declaration.
45
 
46
+ Trailing template arguments that can be deduced [[temp.deduct]] or
47
  obtained from default *template-argument*s may be omitted from the list
48
+ of explicit *template-argument*s. A trailing template parameter pack
49
+ [[temp.variadic]] not otherwise deduced will be deduced as an empty
50
  sequence of template arguments. If all of the template arguments can be
51
  deduced, they may all be omitted; in this case, the empty template
52
  argument list `<>` itself may also be omitted. In contexts where
53
  deduction is done and fails, or in contexts where deduction is not done,
54
  if a template argument list is specified and it, along with any default
 
60
 
61
  ``` cpp
62
  template<class X, class Y> X f(Y);
63
  template<class X, class Y, class ... Z> X g(Y);
64
  void h() {
65
+ int i = f<int>(5.6); // Y deduced as double
66
+ int j = f(5.6); // error: X cannot be deduced
67
+ f<void>(f<int, bool>); // Y for outer f deduced as int (*)(bool)
68
+ f<void>(f<int>); // error: f<int> does not denote a single function template specialization
69
+ int k = g<int>(5.6); // Y deduced as double; Z deduced as an empty sequence
70
+ f<void>(g<int, bool>); // Y for outer f deduced as int (*)(bool),
71
+ // Z deduced as an empty sequence
72
  }
73
  ```
74
 
75
  — *end example*]
76
 
77
  [*Note 1*:
78
 
79
  An empty template argument list can be used to indicate that a given use
80
  refers to a specialization of a function template even when a
81
+ non-template function [[dcl.fct]] is visible that would otherwise be
82
  used. For example:
83
 
84
  ``` cpp
85
  template <class T> int f(T); // #1
86
  int f(int); // #2
 
101
  ``` cpp
102
  template<class X, class Y, class Z> X f(Y,Z);
103
  template<class ... Args> void f2();
104
  void g() {
105
  f<int,const char*,double>("aa",3.0);
106
+ f<int,const char*>("aa",3.0); // Z deduced as double
107
+ f<int>("aa",3.0); // Y deduced as const char*; Z deduced as double
108
  f("aa",3.0); // error: X cannot be deduced
109
  f2<char, short, int, long>(); // OK
110
  }
111
  ```
112
 
113
  — *end example*]
114
 
115
+ Implicit conversions [[conv]] will be performed on a function argument
116
+ to convert it to the type of the corresponding function parameter if the
117
+ parameter type contains no *template-parameter*s that participate in
118
+ template argument deduction.
119
 
120
  [*Note 2*:
121
 
122
  Template parameters do not participate in template argument deduction if
123
  they are explicitly specified. For example,
 
135
  ```
136
 
137
  — *end note*]
138
 
139
  [*Note 3*: Because the explicit template argument list follows the
140
+ function template name, and because constructor templates [[class.ctor]]
141
+ are named without using a function name [[class.qual]], there is no way
142
+ to provide an explicit template argument list for these function
143
+ templates. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
  Template argument deduction can extend the sequence of template
146
  arguments corresponding to a template parameter pack, even when the
147
  sequence contains explicitly specified template arguments.
148
 
149
+ [*Example 4*:
150
 
151
  ``` cpp
152
  template<class ... Types> void f(Types ... values);
153
 
154
  void g() {
155
+ f<int*, float*>(0, 0, 0); // Types deduced as the sequence int*, float*, int
156
  }
157
  ```
158
 
159
  — *end example*]
160