tmp/tmpxnjyu3hn/{from.md → to.md}
RENAMED
|
@@ -22,24 +22,25 @@ explicit-specialization:
|
|
| 22 |
[*Example 1*:
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
template<class T> class stream;
|
| 26 |
|
| 27 |
-
template<> class stream<char> { ... };
|
| 28 |
|
| 29 |
template<class T> class Array { ... };
|
| 30 |
template<class T> void sort(Array<T>& v) { ... }
|
| 31 |
|
| 32 |
-
template<> void sort<
|
|
|
|
| 33 |
```
|
| 34 |
|
| 35 |
-
Given these declarations,
|
| 36 |
-
of
|
| 37 |
-
specializations instantiated from the class template. Similarly,
|
| 38 |
-
|
| 39 |
-
`Array<char*>`; other `Array`
|
| 40 |
-
generated from the template.
|
| 41 |
|
| 42 |
— *end example*]
|
| 43 |
|
| 44 |
The *declaration* in an *explicit-specialization* shall not be an
|
| 45 |
*export-declaration*. An explicit specialization shall not use a
|
|
@@ -53,11 +54,11 @@ An explicit specialization does not introduce a name
|
|
| 53 |
[[basic.scope.scope]]. A declaration of a function template, class
|
| 54 |
template, or variable template being explicitly specialized shall be
|
| 55 |
reachable from the declaration of the explicit specialization.
|
| 56 |
|
| 57 |
[*Note 1*: A declaration, but not a definition of the template is
|
| 58 |
-
|
| 59 |
|
| 60 |
The definition of a class or class template shall be reachable from the
|
| 61 |
declaration of an explicit specialization for a member template of the
|
| 62 |
class or class template.
|
| 63 |
|
|
@@ -203,13 +204,14 @@ can affect whether a program is well-formed according to the relative
|
|
| 203 |
positioning of the explicit specialization declarations and their points
|
| 204 |
of instantiation in the translation unit as specified above and below.
|
| 205 |
When writing a specialization, be careful about its location; or to make
|
| 206 |
it compile will be such a trial as to kindle its self-immolation.
|
| 207 |
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
| 211 |
[[basic.types]].
|
| 212 |
|
| 213 |
[*Example 5*:
|
| 214 |
|
| 215 |
``` cpp
|
|
@@ -220,47 +222,33 @@ X<int>* p; // OK, pointer to declared class
|
|
| 220 |
X<int> x; // error: object of incomplete class X<int>
|
| 221 |
```
|
| 222 |
|
| 223 |
— *end example*]
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
// explicit specialization for sort(Array<int>&)
|
| 236 |
-
// with deduced template-argument of type int
|
| 237 |
-
template<> void sort(Array<int>&);
|
| 238 |
-
```
|
| 239 |
-
|
| 240 |
-
— *end example*]
|
| 241 |
-
|
| 242 |
-
[*Note 2*: An explicit specialization of a constrained template is
|
| 243 |
-
required to satisfy that template’s associated constraints
|
| 244 |
-
[[temp.constr.decl]]. The satisfaction of constraints is determined when
|
| 245 |
-
forming the template name of an explicit specialization in which all
|
| 246 |
-
template arguments are specified [[temp.names]], or, for explicit
|
| 247 |
-
specializations of function templates, during template argument
|
| 248 |
-
deduction [[temp.deduct.decl]] when one or more trailing template
|
| 249 |
-
arguments are left unspecified. — *end note*]
|
| 250 |
|
| 251 |
A function with the same name as a template and a type that exactly
|
| 252 |
matches that of a template specialization is not an explicit
|
| 253 |
specialization [[temp.fct]].
|
| 254 |
|
| 255 |
Whether an explicit specialization of a function or variable template is
|
| 256 |
inline, constexpr, constinit, or consteval is determined by the explicit
|
| 257 |
specialization and is independent of those properties of the template.
|
| 258 |
-
Similarly, attributes
|
| 259 |
-
|
|
|
|
| 260 |
|
| 261 |
-
[*Example
|
| 262 |
|
| 263 |
``` cpp
|
| 264 |
template<class T> void f(T) { ... }
|
| 265 |
template<class T> inline T g(T) { ... }
|
| 266 |
|
|
@@ -279,11 +267,11 @@ template<> void h<int>(int i) {
|
|
| 279 |
An explicit specialization of a static data member of a template or an
|
| 280 |
explicit specialization of a static data member template is a definition
|
| 281 |
if the declaration includes an initializer; otherwise, it is a
|
| 282 |
declaration.
|
| 283 |
|
| 284 |
-
[*Note
|
| 285 |
|
| 286 |
The definition of a static data member of a template for which
|
| 287 |
default-initialization is desired can use functional cast notation
|
| 288 |
[[expr.type.conv]]:
|
| 289 |
|
|
@@ -299,11 +287,11 @@ A member or a member template of a class template may be explicitly
|
|
| 299 |
specialized for a given implicit instantiation of the class template,
|
| 300 |
even if the member or member template is defined in the class template
|
| 301 |
definition. An explicit specialization of a member or member template is
|
| 302 |
specified using the syntax for explicit specialization.
|
| 303 |
|
| 304 |
-
[*Example
|
| 305 |
|
| 306 |
``` cpp
|
| 307 |
template<class T> struct A {
|
| 308 |
void f(T);
|
| 309 |
template<class X1> void g1(T, X1);
|
|
@@ -335,11 +323,11 @@ template<> void A<int>::h(int) { }
|
|
| 335 |
A member or a member template may be nested within many enclosing class
|
| 336 |
templates. In an explicit specialization for such a member, the member
|
| 337 |
declaration shall be preceded by a `template<>` for each enclosing class
|
| 338 |
template that is explicitly specialized.
|
| 339 |
|
| 340 |
-
[*Example
|
| 341 |
|
| 342 |
``` cpp
|
| 343 |
template<class T1> class A {
|
| 344 |
template<class T2> class B {
|
| 345 |
void mf();
|
|
@@ -361,11 +349,11 @@ declaration, the keyword `template` followed by a
|
|
| 361 |
*template-parameter-list* shall be provided instead of the `template<>`
|
| 362 |
preceding the explicit specialization declaration of the member. The
|
| 363 |
types of the *template-parameter*s in the *template-parameter-list*
|
| 364 |
shall be the same as those specified in the primary template definition.
|
| 365 |
|
| 366 |
-
[*Example
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
template <class T1> class A {
|
| 370 |
template<class T2> class B {
|
| 371 |
template<class T3> void mf1(T3);
|
|
@@ -397,10 +385,10 @@ definition for one of the following explicit specializations:
|
|
| 397 |
|
| 398 |
- the explicit specialization of a function template;
|
| 399 |
- the explicit specialization of a member function template;
|
| 400 |
- the explicit specialization of a member function of a class template
|
| 401 |
where the class template specialization to which the member function
|
| 402 |
-
specialization belongs is implicitly instantiated. \[*Note
|
| 403 |
function arguments can be specified in the declaration or definition
|
| 404 |
of a member function of a class template specialization that is
|
| 405 |
explicitly specialized. — *end note*]
|
| 406 |
|
|
|
|
| 22 |
[*Example 1*:
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
template<class T> class stream;
|
| 26 |
|
| 27 |
+
template<> class stream<char> { ... }; // #1
|
| 28 |
|
| 29 |
template<class T> class Array { ... };
|
| 30 |
template<class T> void sort(Array<T>& v) { ... }
|
| 31 |
|
| 32 |
+
template<> void sort<int>(Array<int>&); // #2
|
| 33 |
+
template<> void sort(Array<char*>&); // #3 template argument is deduced[temp.arg.explicit]
|
| 34 |
```
|
| 35 |
|
| 36 |
+
Given these declarations, \#1 will be used as the definition of streams
|
| 37 |
+
of `char`s; other streams will be handled by class template
|
| 38 |
+
specializations instantiated from the class template. Similarly, \#2
|
| 39 |
+
will be used as the sort function for arguments of type `Array<int>` and
|
| 40 |
+
\#3 will be used for arguments of type `Array<char*>`; other `Array`
|
| 41 |
+
types will be sorted by functions generated from the function template.
|
| 42 |
|
| 43 |
— *end example*]
|
| 44 |
|
| 45 |
The *declaration* in an *explicit-specialization* shall not be an
|
| 46 |
*export-declaration*. An explicit specialization shall not use a
|
|
|
|
| 54 |
[[basic.scope.scope]]. A declaration of a function template, class
|
| 55 |
template, or variable template being explicitly specialized shall be
|
| 56 |
reachable from the declaration of the explicit specialization.
|
| 57 |
|
| 58 |
[*Note 1*: A declaration, but not a definition of the template is
|
| 59 |
+
needed. — *end note*]
|
| 60 |
|
| 61 |
The definition of a class or class template shall be reachable from the
|
| 62 |
declaration of an explicit specialization for a member template of the
|
| 63 |
class or class template.
|
| 64 |
|
|
|
|
| 204 |
positioning of the explicit specialization declarations and their points
|
| 205 |
of instantiation in the translation unit as specified above and below.
|
| 206 |
When writing a specialization, be careful about its location; or to make
|
| 207 |
it compile will be such a trial as to kindle its self-immolation.
|
| 208 |
|
| 209 |
+
[*Note 2*:
|
| 210 |
+
|
| 211 |
+
A class template explicit specialization that has been declared but not
|
| 212 |
+
defined can be used exactly like other incompletely-defined classes
|
| 213 |
[[basic.types]].
|
| 214 |
|
| 215 |
[*Example 5*:
|
| 216 |
|
| 217 |
``` cpp
|
|
|
|
| 222 |
X<int> x; // error: object of incomplete class X<int>
|
| 223 |
```
|
| 224 |
|
| 225 |
— *end example*]
|
| 226 |
|
| 227 |
+
— *end note*]
|
| 228 |
+
|
| 229 |
+
[*Note 3*: An explicit specialization of a constrained template needs
|
| 230 |
+
to satisfy that template’s associated constraints [[temp.constr.decl]].
|
| 231 |
+
The satisfaction of constraints is determined when forming the template
|
| 232 |
+
name of an explicit specialization in which all template arguments are
|
| 233 |
+
specified [[temp.names]], or, for explicit specializations of function
|
| 234 |
+
templates, during template argument deduction [[temp.deduct.decl]] when
|
| 235 |
+
one or more trailing template arguments are left
|
| 236 |
+
unspecified. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
A function with the same name as a template and a type that exactly
|
| 239 |
matches that of a template specialization is not an explicit
|
| 240 |
specialization [[temp.fct]].
|
| 241 |
|
| 242 |
Whether an explicit specialization of a function or variable template is
|
| 243 |
inline, constexpr, constinit, or consteval is determined by the explicit
|
| 244 |
specialization and is independent of those properties of the template.
|
| 245 |
+
Similarly, attributes and *function-contract-specifier*s appearing in
|
| 246 |
+
the declaration of a template have no effect on an explicit
|
| 247 |
+
specialization of that template.
|
| 248 |
|
| 249 |
+
[*Example 6*:
|
| 250 |
|
| 251 |
``` cpp
|
| 252 |
template<class T> void f(T) { ... }
|
| 253 |
template<class T> inline T g(T) { ... }
|
| 254 |
|
|
|
|
| 267 |
An explicit specialization of a static data member of a template or an
|
| 268 |
explicit specialization of a static data member template is a definition
|
| 269 |
if the declaration includes an initializer; otherwise, it is a
|
| 270 |
declaration.
|
| 271 |
|
| 272 |
+
[*Note 4*:
|
| 273 |
|
| 274 |
The definition of a static data member of a template for which
|
| 275 |
default-initialization is desired can use functional cast notation
|
| 276 |
[[expr.type.conv]]:
|
| 277 |
|
|
|
|
| 287 |
specialized for a given implicit instantiation of the class template,
|
| 288 |
even if the member or member template is defined in the class template
|
| 289 |
definition. An explicit specialization of a member or member template is
|
| 290 |
specified using the syntax for explicit specialization.
|
| 291 |
|
| 292 |
+
[*Example 7*:
|
| 293 |
|
| 294 |
``` cpp
|
| 295 |
template<class T> struct A {
|
| 296 |
void f(T);
|
| 297 |
template<class X1> void g1(T, X1);
|
|
|
|
| 323 |
A member or a member template may be nested within many enclosing class
|
| 324 |
templates. In an explicit specialization for such a member, the member
|
| 325 |
declaration shall be preceded by a `template<>` for each enclosing class
|
| 326 |
template that is explicitly specialized.
|
| 327 |
|
| 328 |
+
[*Example 8*:
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
template<class T1> class A {
|
| 332 |
template<class T2> class B {
|
| 333 |
void mf();
|
|
|
|
| 349 |
*template-parameter-list* shall be provided instead of the `template<>`
|
| 350 |
preceding the explicit specialization declaration of the member. The
|
| 351 |
types of the *template-parameter*s in the *template-parameter-list*
|
| 352 |
shall be the same as those specified in the primary template definition.
|
| 353 |
|
| 354 |
+
[*Example 9*:
|
| 355 |
|
| 356 |
``` cpp
|
| 357 |
template <class T1> class A {
|
| 358 |
template<class T2> class B {
|
| 359 |
template<class T3> void mf1(T3);
|
|
|
|
| 385 |
|
| 386 |
- the explicit specialization of a function template;
|
| 387 |
- the explicit specialization of a member function template;
|
| 388 |
- the explicit specialization of a member function of a class template
|
| 389 |
where the class template specialization to which the member function
|
| 390 |
+
specialization belongs is implicitly instantiated. \[*Note 5*: Default
|
| 391 |
function arguments can be specified in the declaration or definition
|
| 392 |
of a member function of a class template specialization that is
|
| 393 |
explicitly specialized. — *end note*]
|
| 394 |
|