- tmp/tmpbtpvibdr/{from.md → to.md} +19 -155
tmp/tmpbtpvibdr/{from.md → to.md}
RENAMED
|
@@ -11,18 +11,21 @@ instantiate a function template specialization that can be invoked with
|
|
| 11 |
the call arguments. For each function template, if the argument
|
| 12 |
deduction and checking succeeds, the *template-argument*s (deduced
|
| 13 |
and/or explicit) are used to synthesize the declaration of a single
|
| 14 |
function template specialization which is added to the candidate
|
| 15 |
functions set to be used in overload resolution. If, for a given
|
| 16 |
-
function template, argument deduction fails
|
|
|
|
| 17 |
to the set of candidate functions for that template. The complete set of
|
| 18 |
candidate functions includes all the synthesized declarations and all of
|
| 19 |
the non-template overloaded functions of the same name. The synthesized
|
| 20 |
declarations are treated like any other functions in the remainder of
|
| 21 |
overload resolution, except as explicitly noted in
|
| 22 |
[[over.match.best]].[^9]
|
| 23 |
|
|
|
|
|
|
|
| 24 |
``` cpp
|
| 25 |
template<class T> T max(T a, T b) { return a>b?a:b; }
|
| 26 |
|
| 27 |
void f(int a, int b, char c, char d) {
|
| 28 |
int m1 = max(a,b); // max(int a, int b)
|
|
@@ -39,24 +42,32 @@ int max(int,int);
|
|
| 39 |
|
| 40 |
to the example above would resolve the third call, by providing a
|
| 41 |
function that could be called for `max(a,c)` after using the standard
|
| 42 |
conversion of `char` to `int` for `c`.
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
Here is an example involving conversions on a function argument involved
|
| 45 |
in *template-argument* deduction:
|
| 46 |
|
| 47 |
``` cpp
|
| 48 |
-
template<class T> struct B {
|
| 49 |
-
template<class T> struct D : public B<T> {
|
| 50 |
template<class T> void f(B<T>&);
|
| 51 |
|
| 52 |
void g(B<int>& bi, D<int>& di) {
|
| 53 |
f(bi); // f(bi)
|
| 54 |
f(di); // f((B<int>&)di)
|
| 55 |
}
|
| 56 |
```
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
Here is an example involving conversions on a function argument not
|
| 59 |
involved in *template-parameter* deduction:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
template<class T> void f(T*,int); // #1
|
|
@@ -69,15 +80,19 @@ void h(int* pi, int i, char c) {
|
|
| 69 |
f(i,c); // #2: f<int>(i,c);
|
| 70 |
f(i,i); // #2: f<int>(i,char(i))
|
| 71 |
}
|
| 72 |
```
|
| 73 |
|
|
|
|
|
|
|
| 74 |
Only the signature of a function template specialization is needed to
|
| 75 |
enter the specialization in a set of candidate functions. Therefore only
|
| 76 |
the function template declaration is needed to resolve a call for which
|
| 77 |
a template specialization is a candidate.
|
| 78 |
|
|
|
|
|
|
|
| 79 |
``` cpp
|
| 80 |
template<class T> void f(T); // declaration
|
| 81 |
|
| 82 |
void g() {
|
| 83 |
f("Annemarie"); // call of f<const char*>
|
|
@@ -87,158 +102,7 @@ void g() {
|
|
| 87 |
The call of `f` is well-formed even if the template `f` is only declared
|
| 88 |
and not defined at the point of the call. The program will be ill-formed
|
| 89 |
unless a specialization for `f<const char*>`, either implicitly or
|
| 90 |
explicitly generated, is present in some translation unit.
|
| 91 |
|
| 92 |
-
|
| 93 |
-
[basic.def.odr]: basic.md#basic.def.odr
|
| 94 |
-
[basic.link]: basic.md#basic.link
|
| 95 |
-
[basic.lookup]: basic.md#basic.lookup
|
| 96 |
-
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 97 |
-
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
| 98 |
-
[basic.lookup.qual]: basic.md#basic.lookup.qual
|
| 99 |
-
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 100 |
-
[basic.scope]: basic.md#basic.scope
|
| 101 |
-
[basic.scope.hiding]: basic.md#basic.scope.hiding
|
| 102 |
-
[basic.stc.dynamic.deallocation]: basic.md#basic.stc.dynamic.deallocation
|
| 103 |
-
[basic.types]: basic.md#basic.types
|
| 104 |
-
[class]: class.md#class
|
| 105 |
-
[class.abstract]: class.md#class.abstract
|
| 106 |
-
[class.access]: class.md#class.access
|
| 107 |
-
[class.base.init]: special.md#class.base.init
|
| 108 |
-
[class.derived]: class.md#class.derived
|
| 109 |
-
[class.dtor]: special.md#class.dtor
|
| 110 |
-
[class.friend]: class.md#class.friend
|
| 111 |
-
[class.mem]: class.md#class.mem
|
| 112 |
-
[class.member.lookup]: class.md#class.member.lookup
|
| 113 |
-
[class.qual]: basic.md#class.qual
|
| 114 |
-
[conv]: conv.md#conv
|
| 115 |
-
[conv.array]: conv.md#conv.array
|
| 116 |
-
[conv.func]: conv.md#conv.func
|
| 117 |
-
[conv.integral]: conv.md#conv.integral
|
| 118 |
-
[conv.mem]: conv.md#conv.mem
|
| 119 |
-
[conv.ptr]: conv.md#conv.ptr
|
| 120 |
-
[conv.qual]: conv.md#conv.qual
|
| 121 |
-
[dcl.align]: dcl.md#dcl.align
|
| 122 |
-
[dcl.attr.grammar]: dcl.md#dcl.attr.grammar
|
| 123 |
-
[dcl.dcl]: dcl.md#dcl.dcl
|
| 124 |
-
[dcl.fct]: dcl.md#dcl.fct
|
| 125 |
-
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 126 |
-
[dcl.init]: dcl.md#dcl.init
|
| 127 |
-
[dcl.init.list]: dcl.md#dcl.init.list
|
| 128 |
-
[dcl.meaning]: dcl.md#dcl.meaning
|
| 129 |
-
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 130 |
-
[dcl.type.elab]: dcl.md#dcl.type.elab
|
| 131 |
-
[except.spec]: except.md#except.spec
|
| 132 |
-
[expr.const]: expr.md#expr.const
|
| 133 |
-
[expr.new]: expr.md#expr.new
|
| 134 |
-
[expr.prim.lambda]: expr.md#expr.prim.lambda
|
| 135 |
-
[expr.ref]: expr.md#expr.ref
|
| 136 |
-
[expr.sizeof]: expr.md#expr.sizeof
|
| 137 |
-
[expr.unary.op]: expr.md#expr.unary.op
|
| 138 |
-
[intro.defs]: intro.md#intro.defs
|
| 139 |
-
[lex.string]: lex.md#lex.string
|
| 140 |
-
[namespace.def]: dcl.md#namespace.def
|
| 141 |
-
[namespace.memdef]: dcl.md#namespace.memdef
|
| 142 |
-
[over.ics.rank]: over.md#over.ics.rank
|
| 143 |
-
[over.match.best]: over.md#over.match.best
|
| 144 |
-
[over.match.conv]: over.md#over.match.conv
|
| 145 |
-
[over.match.ref]: over.md#over.match.ref
|
| 146 |
-
[over.over]: over.md#over.over
|
| 147 |
-
[special]: special.md#special
|
| 148 |
-
[support.types]: language.md#support.types
|
| 149 |
-
[temp]: #temp
|
| 150 |
-
[temp.alias]: #temp.alias
|
| 151 |
-
[temp.arg]: #temp.arg
|
| 152 |
-
[temp.arg.explicit]: #temp.arg.explicit
|
| 153 |
-
[temp.arg.nontype]: #temp.arg.nontype
|
| 154 |
-
[temp.arg.template]: #temp.arg.template
|
| 155 |
-
[temp.arg.type]: #temp.arg.type
|
| 156 |
-
[temp.class]: #temp.class
|
| 157 |
-
[temp.class.order]: #temp.class.order
|
| 158 |
-
[temp.class.spec]: #temp.class.spec
|
| 159 |
-
[temp.class.spec.match]: #temp.class.spec.match
|
| 160 |
-
[temp.class.spec.mfunc]: #temp.class.spec.mfunc
|
| 161 |
-
[temp.decls]: #temp.decls
|
| 162 |
-
[temp.deduct]: #temp.deduct
|
| 163 |
-
[temp.deduct.call]: #temp.deduct.call
|
| 164 |
-
[temp.deduct.conv]: #temp.deduct.conv
|
| 165 |
-
[temp.deduct.decl]: #temp.deduct.decl
|
| 166 |
-
[temp.deduct.funcaddr]: #temp.deduct.funcaddr
|
| 167 |
-
[temp.deduct.partial]: #temp.deduct.partial
|
| 168 |
-
[temp.deduct.type]: #temp.deduct.type
|
| 169 |
-
[temp.dep]: #temp.dep
|
| 170 |
-
[temp.dep.candidate]: #temp.dep.candidate
|
| 171 |
-
[temp.dep.constexpr]: #temp.dep.constexpr
|
| 172 |
-
[temp.dep.expr]: #temp.dep.expr
|
| 173 |
-
[temp.dep.res]: #temp.dep.res
|
| 174 |
-
[temp.dep.temp]: #temp.dep.temp
|
| 175 |
-
[temp.dep.type]: #temp.dep.type
|
| 176 |
-
[temp.expl.spec]: #temp.expl.spec
|
| 177 |
-
[temp.explicit]: #temp.explicit
|
| 178 |
-
[temp.fct]: #temp.fct
|
| 179 |
-
[temp.fct.spec]: #temp.fct.spec
|
| 180 |
-
[temp.friend]: #temp.friend
|
| 181 |
-
[temp.func.order]: #temp.func.order
|
| 182 |
-
[temp.inject]: #temp.inject
|
| 183 |
-
[temp.inst]: #temp.inst
|
| 184 |
-
[temp.local]: #temp.local
|
| 185 |
-
[temp.mem]: #temp.mem
|
| 186 |
-
[temp.mem.class]: #temp.mem.class
|
| 187 |
-
[temp.mem.enum]: #temp.mem.enum
|
| 188 |
-
[temp.mem.func]: #temp.mem.func
|
| 189 |
-
[temp.names]: #temp.names
|
| 190 |
-
[temp.nondep]: #temp.nondep
|
| 191 |
-
[temp.over]: #temp.over
|
| 192 |
-
[temp.over.link]: #temp.over.link
|
| 193 |
-
[temp.param]: #temp.param
|
| 194 |
-
[temp.point]: #temp.point
|
| 195 |
-
[temp.res]: #temp.res
|
| 196 |
-
[temp.spec]: #temp.spec
|
| 197 |
-
[temp.static]: #temp.static
|
| 198 |
-
[temp.type]: #temp.type
|
| 199 |
-
[temp.variadic]: #temp.variadic
|
| 200 |
|
| 201 |
-
[^1]: Since template *template-parameter*s and template
|
| 202 |
-
*template-argument*s are treated as types for descriptive purposes,
|
| 203 |
-
the terms *non-type parameter* and *non-type argument* are used to
|
| 204 |
-
refer to non-type, non-template parameters and arguments.
|
| 205 |
-
|
| 206 |
-
[^2]: A `>` that encloses the *type-id* of a `dynamic_cast`,
|
| 207 |
-
`static_cast`, `reinterpret_cast` or `const_cast`, or which encloses
|
| 208 |
-
the *template-argument*s of a subsequent *template-id*, is
|
| 209 |
-
considered nested for the purpose of this description.
|
| 210 |
-
|
| 211 |
-
[^3]: There is no such ambiguity in a default *template-argument*
|
| 212 |
-
because the form of the *template-parameter* determines the
|
| 213 |
-
allowable forms of the *template-argument*.
|
| 214 |
-
|
| 215 |
-
[^4]: There is no way in which they could be used.
|
| 216 |
-
|
| 217 |
-
[^5]: That is, declarations of non-template functions do not merely
|
| 218 |
-
guide overload resolution of function template specializations with
|
| 219 |
-
the same name. If such a non-template function is odr-used (
|
| 220 |
-
[[basic.def.odr]]) in a program, it must be defined; it will not be
|
| 221 |
-
implicitly instantiated using the function template definition.
|
| 222 |
-
|
| 223 |
-
[^6]: Friend declarations do not introduce new names into any scope,
|
| 224 |
-
either when the template is declared or when it is instantiated.
|
| 225 |
-
|
| 226 |
-
[^7]: Default arguments are not considered to be arguments in this
|
| 227 |
-
context; they only become arguments after a function has been
|
| 228 |
-
selected.
|
| 229 |
-
|
| 230 |
-
[^8]: Although the *template-argument* corresponding to a
|
| 231 |
-
*template-parameter* of type `bool` may be deduced from an array
|
| 232 |
-
bound, the resulting value will always be `true` because the array
|
| 233 |
-
bound will be non-zero.
|
| 234 |
-
|
| 235 |
-
[^9]: The parameters of function template specializations contain no
|
| 236 |
-
template parameter types. The set of conversions allowed on deduced
|
| 237 |
-
arguments is limited, because the argument deduction process
|
| 238 |
-
produces function templates with parameters that either match the
|
| 239 |
-
call arguments exactly or differ only in ways that can be bridged by
|
| 240 |
-
the allowed limited conversions. Non-deduced arguments allow the
|
| 241 |
-
full range of conversions. Note also that [[over.match.best]]
|
| 242 |
-
specifies that a non-template function will be given preference over
|
| 243 |
-
a template specialization if the two functions are otherwise equally
|
| 244 |
-
good candidates for an overload match.
|
|
|
|
| 11 |
the call arguments. For each function template, if the argument
|
| 12 |
deduction and checking succeeds, the *template-argument*s (deduced
|
| 13 |
and/or explicit) are used to synthesize the declaration of a single
|
| 14 |
function template specialization which is added to the candidate
|
| 15 |
functions set to be used in overload resolution. If, for a given
|
| 16 |
+
function template, argument deduction fails or the synthesized function
|
| 17 |
+
template specialization would be ill-formed, no such function is added
|
| 18 |
to the set of candidate functions for that template. The complete set of
|
| 19 |
candidate functions includes all the synthesized declarations and all of
|
| 20 |
the non-template overloaded functions of the same name. The synthesized
|
| 21 |
declarations are treated like any other functions in the remainder of
|
| 22 |
overload resolution, except as explicitly noted in
|
| 23 |
[[over.match.best]].[^9]
|
| 24 |
|
| 25 |
+
[*Example 1*:
|
| 26 |
+
|
| 27 |
``` cpp
|
| 28 |
template<class T> T max(T a, T b) { return a>b?a:b; }
|
| 29 |
|
| 30 |
void f(int a, int b, char c, char d) {
|
| 31 |
int m1 = max(a,b); // max(int a, int b)
|
|
|
|
| 42 |
|
| 43 |
to the example above would resolve the third call, by providing a
|
| 44 |
function that could be called for `max(a,c)` after using the standard
|
| 45 |
conversion of `char` to `int` for `c`.
|
| 46 |
|
| 47 |
+
— *end example*]
|
| 48 |
+
|
| 49 |
+
[*Example 2*:
|
| 50 |
+
|
| 51 |
Here is an example involving conversions on a function argument involved
|
| 52 |
in *template-argument* deduction:
|
| 53 |
|
| 54 |
``` cpp
|
| 55 |
+
template<class T> struct B { ... };
|
| 56 |
+
template<class T> struct D : public B<T> { ... };
|
| 57 |
template<class T> void f(B<T>&);
|
| 58 |
|
| 59 |
void g(B<int>& bi, D<int>& di) {
|
| 60 |
f(bi); // f(bi)
|
| 61 |
f(di); // f((B<int>&)di)
|
| 62 |
}
|
| 63 |
```
|
| 64 |
|
| 65 |
+
— *end example*]
|
| 66 |
+
|
| 67 |
+
[*Example 3*:
|
| 68 |
+
|
| 69 |
Here is an example involving conversions on a function argument not
|
| 70 |
involved in *template-parameter* deduction:
|
| 71 |
|
| 72 |
``` cpp
|
| 73 |
template<class T> void f(T*,int); // #1
|
|
|
|
| 80 |
f(i,c); // #2: f<int>(i,c);
|
| 81 |
f(i,i); // #2: f<int>(i,char(i))
|
| 82 |
}
|
| 83 |
```
|
| 84 |
|
| 85 |
+
— *end example*]
|
| 86 |
+
|
| 87 |
Only the signature of a function template specialization is needed to
|
| 88 |
enter the specialization in a set of candidate functions. Therefore only
|
| 89 |
the function template declaration is needed to resolve a call for which
|
| 90 |
a template specialization is a candidate.
|
| 91 |
|
| 92 |
+
[*Example 4*:
|
| 93 |
+
|
| 94 |
``` cpp
|
| 95 |
template<class T> void f(T); // declaration
|
| 96 |
|
| 97 |
void g() {
|
| 98 |
f("Annemarie"); // call of f<const char*>
|
|
|
|
| 102 |
The call of `f` is well-formed even if the template `f` is only declared
|
| 103 |
and not defined at the point of the call. The program will be ill-formed
|
| 104 |
unless a specialization for `f<const char*>`, either implicitly or
|
| 105 |
explicitly generated, is present in some translation unit.
|
| 106 |
|
| 107 |
+
— *end example*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|