tmp/tmpkg3n0_5i/{from.md → to.md}
RENAMED
|
@@ -14,11 +14,11 @@ An explicit specialization of any of the following:
|
|
| 14 |
|
| 15 |
can be declared by a declaration introduced by `template<>`; that is:
|
| 16 |
|
| 17 |
``` bnf
|
| 18 |
explicit-specialization:
|
| 19 |
-
|
| 20 |
```
|
| 21 |
|
| 22 |
[*Example 1*:
|
| 23 |
|
| 24 |
``` cpp
|
|
@@ -39,10 +39,13 @@ specializations instantiated from the class template. Similarly,
|
|
| 39 |
`Array<char*>`; other `Array` types will be sorted by functions
|
| 40 |
generated from the template.
|
| 41 |
|
| 42 |
— *end example*]
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
An explicit specialization may be declared in any scope in which the
|
| 45 |
corresponding primary template may be defined ([[namespace.memdef]],
|
| 46 |
[[class.mem]], [[temp.mem]]).
|
| 47 |
|
| 48 |
A declaration of a function template, class template, or variable
|
|
@@ -73,12 +76,12 @@ enumeration, a member class template, a static data member, or a static
|
|
| 73 |
data member template of a class template may be explicitly specialized
|
| 74 |
for a class specialization that is implicitly instantiated; in this
|
| 75 |
case, the definition of the class template shall precede the explicit
|
| 76 |
specialization for the member of the class template. If such an explicit
|
| 77 |
specialization for the member of a class template names an
|
| 78 |
-
implicitly-declared special member function
|
| 79 |
-
|
| 80 |
|
| 81 |
A member of an explicitly specialized class is not implicitly
|
| 82 |
instantiated from the member declaration of the class template; instead,
|
| 83 |
the member of the class template specialization shall itself be
|
| 84 |
explicitly defined if its definition is required. In this case, the
|
|
@@ -172,11 +175,11 @@ template<class T> struct A {
|
|
| 172 |
};
|
| 173 |
template<> enum A<int>::E : int { eint }; // OK
|
| 174 |
template<> enum class A<int>::S : int { sint }; // OK
|
| 175 |
template<class T> enum A<T>::E : T { eT };
|
| 176 |
template<class T> enum class A<T>::S : T { sT };
|
| 177 |
-
template<> enum A<char>::E : char { echar }; //
|
| 178 |
// when A<char> was instantiated
|
| 179 |
template<> enum class A<char>::S : char { schar }; // OK
|
| 180 |
```
|
| 181 |
|
| 182 |
— *end example*]
|
|
@@ -220,12 +223,12 @@ template<> class N::Y<short> { ... }; // OK: specialization in enclosing nam
|
|
| 220 |
|
| 221 |
— *end example*]
|
| 222 |
|
| 223 |
A *simple-template-id* that names a class template explicit
|
| 224 |
specialization that has been declared but not defined can be used
|
| 225 |
-
exactly like the names of other incompletely-defined classes
|
| 226 |
-
[[basic.types]]
|
| 227 |
|
| 228 |
[*Example 6*:
|
| 229 |
|
| 230 |
``` cpp
|
| 231 |
template<class T> class X; // X is a class template
|
|
@@ -252,18 +255,27 @@ template<class T> void sort(Array<T>& v);
|
|
| 252 |
template<> void sort(Array<int>&);
|
| 253 |
```
|
| 254 |
|
| 255 |
— *end example*]
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
A function with the same name as a template and a type that exactly
|
| 258 |
matches that of a template specialization is not an explicit
|
| 259 |
-
specialization
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
|
| 266 |
[*Example 8*:
|
| 267 |
|
| 268 |
``` cpp
|
| 269 |
template<class T> void f(T) { ... }
|
|
@@ -278,11 +290,11 @@ template<> int g<>(int) { ... } // OK: not inline
|
|
| 278 |
An explicit specialization of a static data member of a template or an
|
| 279 |
explicit specialization of a static data member template is a definition
|
| 280 |
if the declaration includes an initializer; otherwise, it is a
|
| 281 |
declaration.
|
| 282 |
|
| 283 |
-
[*Note
|
| 284 |
|
| 285 |
The definition of a static data member of a template that requires
|
| 286 |
default-initialization must use a *braced-init-list*:
|
| 287 |
|
| 288 |
``` cpp
|
|
@@ -352,11 +364,11 @@ template<> template<> void A<char>::B<char>::mf();
|
|
| 352 |
In an explicit specialization declaration for a member of a class
|
| 353 |
template or a member template that appears in namespace scope, the
|
| 354 |
member template and some of its enclosing class templates may remain
|
| 355 |
unspecialized, except that the declaration shall not explicitly
|
| 356 |
specialize a class member template if its enclosing class templates are
|
| 357 |
-
not explicitly specialized as well. In such explicit specialization
|
| 358 |
declaration, the keyword `template` followed by a
|
| 359 |
*template-parameter-list* shall be provided instead of the `template<>`
|
| 360 |
preceding the explicit specialization declaration of the member. The
|
| 361 |
types of the *template-parameter*s in the *template-parameter-list*
|
| 362 |
shall be the same as those specified in the primary template definition.
|
|
@@ -375,11 +387,11 @@ template <> template <class X>
|
|
| 375 |
template <class T> void mf1(T);
|
| 376 |
};
|
| 377 |
template <> template <> template<class T>
|
| 378 |
void A<int>::B<double>::mf1(T t) { }
|
| 379 |
template <class Y> template <>
|
| 380 |
-
void A<Y>::B<double>::mf2() { } //
|
| 381 |
// its enclosing class template A is not
|
| 382 |
```
|
| 383 |
|
| 384 |
— *end example*]
|
| 385 |
|
|
@@ -395,10 +407,10 @@ definition for one of the following explicit specializations:
|
|
| 395 |
|
| 396 |
- the explicit specialization of a function template;
|
| 397 |
- the explicit specialization of a member function template;
|
| 398 |
- the explicit specialization of a member function of a class template
|
| 399 |
where the class template specialization to which the member function
|
| 400 |
-
specialization belongs is implicitly instantiated. \[*Note
|
| 401 |
function arguments may be specified in the declaration or definition
|
| 402 |
of a member function of a class template specialization that is
|
| 403 |
explicitly specialized. — *end note*]
|
| 404 |
|
|
|
|
| 14 |
|
| 15 |
can be declared by a declaration introduced by `template<>`; that is:
|
| 16 |
|
| 17 |
``` bnf
|
| 18 |
explicit-specialization:
|
| 19 |
+
template '<' '>' declaration
|
| 20 |
```
|
| 21 |
|
| 22 |
[*Example 1*:
|
| 23 |
|
| 24 |
``` cpp
|
|
|
|
| 39 |
`Array<char*>`; other `Array` types will be sorted by functions
|
| 40 |
generated from the template.
|
| 41 |
|
| 42 |
— *end example*]
|
| 43 |
|
| 44 |
+
An explicit specialization shall not use a *storage-class-specifier*
|
| 45 |
+
[[dcl.stc]] other than `thread_local`.
|
| 46 |
+
|
| 47 |
An explicit specialization may be declared in any scope in which the
|
| 48 |
corresponding primary template may be defined ([[namespace.memdef]],
|
| 49 |
[[class.mem]], [[temp.mem]]).
|
| 50 |
|
| 51 |
A declaration of a function template, class template, or variable
|
|
|
|
| 76 |
data member template of a class template may be explicitly specialized
|
| 77 |
for a class specialization that is implicitly instantiated; in this
|
| 78 |
case, the definition of the class template shall precede the explicit
|
| 79 |
specialization for the member of the class template. If such an explicit
|
| 80 |
specialization for the member of a class template names an
|
| 81 |
+
implicitly-declared special member function [[special]], the program is
|
| 82 |
+
ill-formed.
|
| 83 |
|
| 84 |
A member of an explicitly specialized class is not implicitly
|
| 85 |
instantiated from the member declaration of the class template; instead,
|
| 86 |
the member of the class template specialization shall itself be
|
| 87 |
explicitly defined if its definition is required. In this case, the
|
|
|
|
| 175 |
};
|
| 176 |
template<> enum A<int>::E : int { eint }; // OK
|
| 177 |
template<> enum class A<int>::S : int { sint }; // OK
|
| 178 |
template<class T> enum A<T>::E : T { eT };
|
| 179 |
template<class T> enum class A<T>::S : T { sT };
|
| 180 |
+
template<> enum A<char>::E : char { echar }; // error: A<char>::E was instantiated
|
| 181 |
// when A<char> was instantiated
|
| 182 |
template<> enum class A<char>::S : char { schar }; // OK
|
| 183 |
```
|
| 184 |
|
| 185 |
— *end example*]
|
|
|
|
| 223 |
|
| 224 |
— *end example*]
|
| 225 |
|
| 226 |
A *simple-template-id* that names a class template explicit
|
| 227 |
specialization that has been declared but not defined can be used
|
| 228 |
+
exactly like the names of other incompletely-defined classes
|
| 229 |
+
[[basic.types]].
|
| 230 |
|
| 231 |
[*Example 6*:
|
| 232 |
|
| 233 |
``` cpp
|
| 234 |
template<class T> class X; // X is a class template
|
|
|
|
| 255 |
template<> void sort(Array<int>&);
|
| 256 |
```
|
| 257 |
|
| 258 |
— *end example*]
|
| 259 |
|
| 260 |
+
[*Note 2*: An explicit specialization of a constrained template is
|
| 261 |
+
required to satisfy that template’s associated constraints
|
| 262 |
+
[[temp.constr.decl]]. The satisfaction of constraints is determined when
|
| 263 |
+
forming the template name of an explicit specialization in which all
|
| 264 |
+
template arguments are specified [[temp.names]], or, for explicit
|
| 265 |
+
specializations of function templates, during template argument
|
| 266 |
+
deduction [[temp.deduct.decl]] when one or more trailing template
|
| 267 |
+
arguments are left unspecified. — *end note*]
|
| 268 |
+
|
| 269 |
A function with the same name as a template and a type that exactly
|
| 270 |
matches that of a template specialization is not an explicit
|
| 271 |
+
specialization [[temp.fct]].
|
| 272 |
|
| 273 |
+
Whether an explicit specialization of a function or variable template is
|
| 274 |
+
inline, constexpr, or an immediate function is determined by the
|
| 275 |
+
explicit specialization and is independent of those properties of the
|
| 276 |
+
template.
|
| 277 |
|
| 278 |
[*Example 8*:
|
| 279 |
|
| 280 |
``` cpp
|
| 281 |
template<class T> void f(T) { ... }
|
|
|
|
| 290 |
An explicit specialization of a static data member of a template or an
|
| 291 |
explicit specialization of a static data member template is a definition
|
| 292 |
if the declaration includes an initializer; otherwise, it is a
|
| 293 |
declaration.
|
| 294 |
|
| 295 |
+
[*Note 3*:
|
| 296 |
|
| 297 |
The definition of a static data member of a template that requires
|
| 298 |
default-initialization must use a *braced-init-list*:
|
| 299 |
|
| 300 |
``` cpp
|
|
|
|
| 364 |
In an explicit specialization declaration for a member of a class
|
| 365 |
template or a member template that appears in namespace scope, the
|
| 366 |
member template and some of its enclosing class templates may remain
|
| 367 |
unspecialized, except that the declaration shall not explicitly
|
| 368 |
specialize a class member template if its enclosing class templates are
|
| 369 |
+
not explicitly specialized as well. In such an explicit specialization
|
| 370 |
declaration, the keyword `template` followed by a
|
| 371 |
*template-parameter-list* shall be provided instead of the `template<>`
|
| 372 |
preceding the explicit specialization declaration of the member. The
|
| 373 |
types of the *template-parameter*s in the *template-parameter-list*
|
| 374 |
shall be the same as those specified in the primary template definition.
|
|
|
|
| 387 |
template <class T> void mf1(T);
|
| 388 |
};
|
| 389 |
template <> template <> template<class T>
|
| 390 |
void A<int>::B<double>::mf1(T t) { }
|
| 391 |
template <class Y> template <>
|
| 392 |
+
void A<Y>::B<double>::mf2() { } // error: B<double> is specialized but
|
| 393 |
// its enclosing class template A is not
|
| 394 |
```
|
| 395 |
|
| 396 |
— *end example*]
|
| 397 |
|
|
|
|
| 407 |
|
| 408 |
- the explicit specialization of a function template;
|
| 409 |
- the explicit specialization of a member function template;
|
| 410 |
- the explicit specialization of a member function of a class template
|
| 411 |
where the class template specialization to which the member function
|
| 412 |
+
specialization belongs is implicitly instantiated. \[*Note 4*: Default
|
| 413 |
function arguments may be specified in the declaration or definition
|
| 414 |
of a member function of a class template specialization that is
|
| 415 |
explicitly specialized. — *end note*]
|
| 416 |
|