From Jason Turner

[temp.spec]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbtgzrt0d/{from.md → to.md} +56 -87
tmp/tmpbtgzrt0d/{from.md → to.md} RENAMED
@@ -25,13 +25,12 @@ variable template, a class template, a member of a class template, or a
25
  member template. An explicit specialization declaration is introduced by
26
  `template<>`. In an explicit specialization declaration for a variable
27
  template, a class template, a member of a class template, or a class
28
  member template, the variable or class that is explicitly specialized
29
  shall be specified with a *simple-template-id*. In the explicit
30
- specialization declaration for a function template or a member function
31
- template, the function or member function explicitly specialized may be
32
- specified using a *template-id*.
33
 
34
  [*Example 1*:
35
 
36
  ``` cpp
37
  template<class T = int> struct A {
@@ -364,13 +363,13 @@ void g(S<int>& sr) {
364
  };
365
  ```
366
 
367
  — *end example*]
368
 
369
- If a function template or a member function template specialization is
370
- used in a way that involves overload resolution, a declaration of the
371
- specialization is implicitly instantiated [[temp.over]].
372
 
373
  An implementation shall not implicitly instantiate a function template,
374
  a variable template, a member template, a non-virtual member function, a
375
  member class or static data member of a templated class, or a
376
  substatement of a constexpr if statement [[stmt.if]], unless such
@@ -425,18 +424,18 @@ void g(A a, A b, A c) {
425
  }
426
  ```
427
 
428
  — *end example*]
429
 
430
- The *noexcept-specifier* of a function template specialization is not
431
- instantiated along with the function declaration; it is instantiated
432
- when needed [[except.spec]]. If such an *noexcept-specifier* is needed
 
433
  but has not yet been instantiated, the dependent names are looked up,
434
  the semantics constraints are checked, and the instantiation of any
435
- template used in the *noexcept-specifier* is done as if it were being
436
- done as part of instantiating the declaration of the specialization at
437
- that point.
438
 
439
  [*Note 6*: [[temp.point]] defines the point of instantiation of a
440
  template specialization. — *end note*]
441
 
442
  There is an *implementation-defined* quantity that specifies the limit
@@ -555,11 +554,11 @@ instantiation is for a variable template specialization, the
555
  template<class T> class Array { void mf(); };
556
  template class Array<char>;
557
  template void Array<int>::mf();
558
 
559
  template<class T> void sort(Array<T>& v) { ... }
560
- template void sort(Array<char>&); // argument is deduced here
561
 
562
  namespace N {
563
  template<class T> void f(T&) { }
564
  }
565
  template void N::f<int>(int&);
@@ -584,11 +583,11 @@ The *declaration* in an *explicit-instantiation* and the *declaration*
584
  produced by the corresponding substitution into the templated function,
585
  variable, or class are two declarations of the same entity.
586
 
587
  [*Note 1*:
588
 
589
- These declarations are required to have matching types as specified in 
590
  [[basic.link]], except as specified in  [[except.spec]].
591
 
592
  [*Example 2*:
593
 
594
  ``` cpp
@@ -596,11 +595,11 @@ template<typename T> T var = {};
596
  template float var<float>; // OK, instantiated variable has type float
597
  template int var<int[16]>[]; // OK, absence of major array bound is permitted
598
  template int *var<int>; // error: instantiated variable has type int
599
 
600
  template<typename T> auto av = T();
601
- template int av<int>; // OK, variable with type int can be redeclared with type auto
602
 
603
  template<typename T> auto f() {}
604
  template void f<int>(); // error: function with deduced return type
605
  // redeclared with non-deduced return type[dcl.spec.auto]
606
  ```
@@ -620,36 +619,18 @@ that template, the explicit instantiation has no effect. Otherwise, for
620
  an explicit instantiation definition, the definition of a function
621
  template, a variable template, a member function template, or a member
622
  function or static data member of a class template shall be present in
623
  every translation unit in which it is explicitly instantiated.
624
 
625
- A trailing *template-argument* can be left unspecified in an explicit
626
- instantiation of a function template specialization or of a member
627
- function template specialization provided it can be deduced
628
- [[temp.deduct.decl]]. If all template arguments can be deduced, the
629
- empty template argument list `<>` may be omitted.
630
-
631
- [*Example 3*:
632
-
633
- ``` cpp
634
- template<class T> class Array { ... };
635
- template<class T> void sort(Array<T>& v) { ... }
636
-
637
- // instantiate sort(Array<int>&) -- template-argument deduced
638
- template void sort<>(Array<int>&);
639
- ```
640
-
641
- — *end example*]
642
-
643
- [*Note 2*: An explicit instantiation of a constrained template is
644
- required to satisfy that template’s associated constraints
645
- [[temp.constr.decl]]. The satisfaction of constraints is determined when
646
- forming the template name of an explicit instantiation in which all
647
- template arguments are specified [[temp.names]], or, for explicit
648
- instantiations of function templates, during template argument deduction
649
- [[temp.deduct.decl]] when one or more trailing template arguments are
650
- left unspecified. — *end note*]
651
 
652
  An explicit instantiation that names a class template specialization is
653
  also an explicit instantiation of the same kind (declaration or
654
  definition) of each of its direct non-template members that has not been
655
  previously explicitly specialized in the translation unit containing the
@@ -689,11 +670,11 @@ An explicit instantiation declaration shall not name a specialization of
689
  a template with internal linkage.
690
 
691
  An explicit instantiation does not constitute a use of a default
692
  argument, so default argument instantiation is not done.
693
 
694
- [*Example 4*:
695
 
696
  ``` cpp
697
  char* p = 0;
698
  template<class T> T g(T x = &p) { return x; }
699
  template int g<int>(int); // OK even though &p isn't an int.
@@ -725,24 +706,25 @@ explicit-specialization:
725
  [*Example 1*:
726
 
727
  ``` cpp
728
  template<class T> class stream;
729
 
730
- template<> class stream<char> { ... };
731
 
732
  template<class T> class Array { ... };
733
  template<class T> void sort(Array<T>& v) { ... }
734
 
735
- template<> void sort<char*>(Array<char*>&);
 
736
  ```
737
 
738
- Given these declarations, `stream<char>` will be used as the definition
739
- of streams of `char`s; other streams will be handled by class template
740
- specializations instantiated from the class template. Similarly,
741
- `sort<char*>` will be used as the sort function for arguments of type
742
- `Array<char*>`; other `Array` types will be sorted by functions
743
- generated from the template.
744
 
745
  — *end example*]
746
 
747
  The *declaration* in an *explicit-specialization* shall not be an
748
  *export-declaration*. An explicit specialization shall not use a
@@ -756,11 +738,11 @@ An explicit specialization does not introduce a name
756
  [[basic.scope.scope]]. A declaration of a function template, class
757
  template, or variable template being explicitly specialized shall be
758
  reachable from the declaration of the explicit specialization.
759
 
760
  [*Note 1*: A declaration, but not a definition of the template is
761
- required. — *end note*]
762
 
763
  The definition of a class or class template shall be reachable from the
764
  declaration of an explicit specialization for a member template of the
765
  class or class template.
766
 
@@ -906,13 +888,14 @@ can affect whether a program is well-formed according to the relative
906
  positioning of the explicit specialization declarations and their points
907
  of instantiation in the translation unit as specified above and below.
908
  When writing a specialization, be careful about its location; or to make
909
  it compile will be such a trial as to kindle its self-immolation.
910
 
911
- A *simple-template-id* that names a class template explicit
912
- specialization that has been declared but not defined can be used
913
- exactly like the names of other incompletely-defined classes
 
914
  [[basic.types]].
915
 
916
  [*Example 5*:
917
 
918
  ``` cpp
@@ -923,47 +906,33 @@ X<int>* p; // OK, pointer to declared class
923
  X<int> x; // error: object of incomplete class X<int>
924
  ```
925
 
926
  — *end example*]
927
 
928
- A trailing *template-argument* can be left unspecified in the
929
- *template-id* naming an explicit function template specialization
930
- provided it can be deduced [[temp.deduct.decl]].
931
-
932
- [*Example 6*:
933
-
934
- ``` cpp
935
- template<class T> class Array { ... };
936
- template<class T> void sort(Array<T>& v);
937
-
938
- // explicit specialization for sort(Array<int>&)
939
- // with deduced template-argument of type int
940
- template<> void sort(Array<int>&);
941
- ```
942
-
943
- — *end example*]
944
-
945
- [*Note 2*: An explicit specialization of a constrained template is
946
- required to satisfy that template’s associated constraints
947
- [[temp.constr.decl]]. The satisfaction of constraints is determined when
948
- forming the template name of an explicit specialization in which all
949
- template arguments are specified [[temp.names]], or, for explicit
950
- specializations of function templates, during template argument
951
- deduction [[temp.deduct.decl]] when one or more trailing template
952
- arguments are left unspecified. — *end note*]
953
 
954
  A function with the same name as a template and a type that exactly
955
  matches that of a template specialization is not an explicit
956
  specialization [[temp.fct]].
957
 
958
  Whether an explicit specialization of a function or variable template is
959
  inline, constexpr, constinit, or consteval is determined by the explicit
960
  specialization and is independent of those properties of the template.
961
- Similarly, attributes appearing in the declaration of a template have no
962
- effect on an explicit specialization of that template.
 
963
 
964
- [*Example 7*:
965
 
966
  ``` cpp
967
  template<class T> void f(T) { ... }
968
  template<class T> inline T g(T) { ... }
969
 
@@ -982,11 +951,11 @@ template<> void h<int>(int i) {
982
  An explicit specialization of a static data member of a template or an
983
  explicit specialization of a static data member template is a definition
984
  if the declaration includes an initializer; otherwise, it is a
985
  declaration.
986
 
987
- [*Note 3*:
988
 
989
  The definition of a static data member of a template for which
990
  default-initialization is desired can use functional cast notation
991
  [[expr.type.conv]]:
992
 
@@ -1002,11 +971,11 @@ A member or a member template of a class template may be explicitly
1002
  specialized for a given implicit instantiation of the class template,
1003
  even if the member or member template is defined in the class template
1004
  definition. An explicit specialization of a member or member template is
1005
  specified using the syntax for explicit specialization.
1006
 
1007
- [*Example 8*:
1008
 
1009
  ``` cpp
1010
  template<class T> struct A {
1011
  void f(T);
1012
  template<class X1> void g1(T, X1);
@@ -1038,11 +1007,11 @@ template<> void A<int>::h(int) { }
1038
  A member or a member template may be nested within many enclosing class
1039
  templates. In an explicit specialization for such a member, the member
1040
  declaration shall be preceded by a `template<>` for each enclosing class
1041
  template that is explicitly specialized.
1042
 
1043
- [*Example 9*:
1044
 
1045
  ``` cpp
1046
  template<class T1> class A {
1047
  template<class T2> class B {
1048
  void mf();
@@ -1064,11 +1033,11 @@ declaration, the keyword `template` followed by a
1064
  *template-parameter-list* shall be provided instead of the `template<>`
1065
  preceding the explicit specialization declaration of the member. The
1066
  types of the *template-parameter*s in the *template-parameter-list*
1067
  shall be the same as those specified in the primary template definition.
1068
 
1069
- [*Example 10*:
1070
 
1071
  ``` cpp
1072
  template <class T1> class A {
1073
  template<class T2> class B {
1074
  template<class T3> void mf1(T3);
@@ -1100,10 +1069,10 @@ definition for one of the following explicit specializations:
1100
 
1101
  - the explicit specialization of a function template;
1102
  - the explicit specialization of a member function template;
1103
  - the explicit specialization of a member function of a class template
1104
  where the class template specialization to which the member function
1105
- specialization belongs is implicitly instantiated. \[*Note 4*: Default
1106
  function arguments can be specified in the declaration or definition
1107
  of a member function of a class template specialization that is
1108
  explicitly specialized. — *end note*]
1109
 
 
25
  member template. An explicit specialization declaration is introduced by
26
  `template<>`. In an explicit specialization declaration for a variable
27
  template, a class template, a member of a class template, or a class
28
  member template, the variable or class that is explicitly specialized
29
  shall be specified with a *simple-template-id*. In the explicit
30
+ specialization declaration for a function template, the function
31
+ explicitly specialized may be specified using a *template-id*.
 
32
 
33
  [*Example 1*:
34
 
35
  ``` cpp
36
  template<class T = int> struct A {
 
363
  };
364
  ```
365
 
366
  — *end example*]
367
 
368
+ If a function template specialization is used in a way that involves
369
+ overload resolution, a declaration of the specialization is implicitly
370
+ instantiated [[temp.over]].
371
 
372
  An implementation shall not implicitly instantiate a function template,
373
  a variable template, a member template, a non-virtual member function, a
374
  member class or static data member of a templated class, or a
375
  substatement of a constexpr if statement [[stmt.if]], unless such
 
424
  }
425
  ```
426
 
427
  — *end example*]
428
 
429
+ The *noexcept-specifier* and *function-contract-specifier*s of a
430
+ function template specialization are not instantiated along with the
431
+ function declaration; they are instantiated when needed
432
+ [[except.spec]], [[dcl.contract.func]]. If such a specifier is needed
433
  but has not yet been instantiated, the dependent names are looked up,
434
  the semantics constraints are checked, and the instantiation of any
435
+ template used in the specifier is done as if it were being done as part
436
+ of instantiating the declaration of the specialization at that point.
 
437
 
438
  [*Note 6*: [[temp.point]] defines the point of instantiation of a
439
  template specialization. — *end note*]
440
 
441
  There is an *implementation-defined* quantity that specifies the limit
 
554
  template<class T> class Array { void mf(); };
555
  template class Array<char>;
556
  template void Array<int>::mf();
557
 
558
  template<class T> void sort(Array<T>& v) { ... }
559
+ template void sort(Array<char>&); // argument is deduced here[temp.arg.explicit]
560
 
561
  namespace N {
562
  template<class T> void f(T&) { }
563
  }
564
  template void N::f<int>(int&);
 
583
  produced by the corresponding substitution into the templated function,
584
  variable, or class are two declarations of the same entity.
585
 
586
  [*Note 1*:
587
 
588
+ These declarations need to have matching types as specified in 
589
  [[basic.link]], except as specified in  [[except.spec]].
590
 
591
  [*Example 2*:
592
 
593
  ``` cpp
 
595
  template float var<float>; // OK, instantiated variable has type float
596
  template int var<int[16]>[]; // OK, absence of major array bound is permitted
597
  template int *var<int>; // error: instantiated variable has type int
598
 
599
  template<typename T> auto av = T();
600
+ template int av<int>; // OK, variable with type auto can be redeclared with type int
601
 
602
  template<typename T> auto f() {}
603
  template void f<int>(); // error: function with deduced return type
604
  // redeclared with non-deduced return type[dcl.spec.auto]
605
  ```
 
619
  an explicit instantiation definition, the definition of a function
620
  template, a variable template, a member function template, or a member
621
  function or static data member of a class template shall be present in
622
  every translation unit in which it is explicitly instantiated.
623
 
624
+ [*Note 2*: An explicit instantiation of a constrained template needs to
625
+ satisfy that template’s associated constraints [[temp.constr.decl]]. The
626
+ satisfaction of constraints is determined when forming the template name
627
+ of an explicit instantiation in which all template arguments are
628
+ specified [[temp.names]], or, for explicit instantiations of function
629
+ templates, during template argument deduction [[temp.deduct.decl]] when
630
+ one or more trailing template arguments are left
631
+ unspecified. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
632
 
633
  An explicit instantiation that names a class template specialization is
634
  also an explicit instantiation of the same kind (declaration or
635
  definition) of each of its direct non-template members that has not been
636
  previously explicitly specialized in the translation unit containing the
 
670
  a template with internal linkage.
671
 
672
  An explicit instantiation does not constitute a use of a default
673
  argument, so default argument instantiation is not done.
674
 
675
+ [*Example 3*:
676
 
677
  ``` cpp
678
  char* p = 0;
679
  template<class T> T g(T x = &p) { return x; }
680
  template int g<int>(int); // OK even though &p isn't an int.
 
706
  [*Example 1*:
707
 
708
  ``` cpp
709
  template<class T> class stream;
710
 
711
+ template<> class stream<char> { ... }; // #1
712
 
713
  template<class T> class Array { ... };
714
  template<class T> void sort(Array<T>& v) { ... }
715
 
716
+ template<> void sort<int>(Array<int>&); // #2
717
+ template<> void sort(Array<char*>&); // #3 template argument is deduced[temp.arg.explicit]
718
  ```
719
 
720
+ Given these declarations, \#1 will be used as the definition of streams
721
+ of `char`s; other streams will be handled by class template
722
+ specializations instantiated from the class template. Similarly, \#2
723
+ will be used as the sort function for arguments of type `Array<int>` and
724
+ \#3 will be used for arguments of type `Array<char*>`; other `Array`
725
+ types will be sorted by functions generated from the function template.
726
 
727
  — *end example*]
728
 
729
  The *declaration* in an *explicit-specialization* shall not be an
730
  *export-declaration*. An explicit specialization shall not use a
 
738
  [[basic.scope.scope]]. A declaration of a function template, class
739
  template, or variable template being explicitly specialized shall be
740
  reachable from the declaration of the explicit specialization.
741
 
742
  [*Note 1*: A declaration, but not a definition of the template is
743
+ needed. — *end note*]
744
 
745
  The definition of a class or class template shall be reachable from the
746
  declaration of an explicit specialization for a member template of the
747
  class or class template.
748
 
 
888
  positioning of the explicit specialization declarations and their points
889
  of instantiation in the translation unit as specified above and below.
890
  When writing a specialization, be careful about its location; or to make
891
  it compile will be such a trial as to kindle its self-immolation.
892
 
893
+ [*Note 2*:
894
+
895
+ A class template explicit specialization that has been declared but not
896
+ defined can be used exactly like other incompletely-defined classes
897
  [[basic.types]].
898
 
899
  [*Example 5*:
900
 
901
  ``` cpp
 
906
  X<int> x; // error: object of incomplete class X<int>
907
  ```
908
 
909
  — *end example*]
910
 
911
+ *end note*]
912
+
913
+ [*Note 3*: An explicit specialization of a constrained template needs
914
+ to satisfy that template’s associated constraints [[temp.constr.decl]].
915
+ The satisfaction of constraints is determined when forming the template
916
+ name of an explicit specialization in which all template arguments are
917
+ specified [[temp.names]], or, for explicit specializations of function
918
+ templates, during template argument deduction [[temp.deduct.decl]] when
919
+ one or more trailing template arguments are left
920
+ unspecified. — *end note*]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
921
 
922
  A function with the same name as a template and a type that exactly
923
  matches that of a template specialization is not an explicit
924
  specialization [[temp.fct]].
925
 
926
  Whether an explicit specialization of a function or variable template is
927
  inline, constexpr, constinit, or consteval is determined by the explicit
928
  specialization and is independent of those properties of the template.
929
+ Similarly, attributes and *function-contract-specifier*s appearing in
930
+ the declaration of a template have no effect on an explicit
931
+ specialization of that template.
932
 
933
+ [*Example 6*:
934
 
935
  ``` cpp
936
  template<class T> void f(T) { ... }
937
  template<class T> inline T g(T) { ... }
938
 
 
951
  An explicit specialization of a static data member of a template or an
952
  explicit specialization of a static data member template is a definition
953
  if the declaration includes an initializer; otherwise, it is a
954
  declaration.
955
 
956
+ [*Note 4*:
957
 
958
  The definition of a static data member of a template for which
959
  default-initialization is desired can use functional cast notation
960
  [[expr.type.conv]]:
961
 
 
971
  specialized for a given implicit instantiation of the class template,
972
  even if the member or member template is defined in the class template
973
  definition. An explicit specialization of a member or member template is
974
  specified using the syntax for explicit specialization.
975
 
976
+ [*Example 7*:
977
 
978
  ``` cpp
979
  template<class T> struct A {
980
  void f(T);
981
  template<class X1> void g1(T, X1);
 
1007
  A member or a member template may be nested within many enclosing class
1008
  templates. In an explicit specialization for such a member, the member
1009
  declaration shall be preceded by a `template<>` for each enclosing class
1010
  template that is explicitly specialized.
1011
 
1012
+ [*Example 8*:
1013
 
1014
  ``` cpp
1015
  template<class T1> class A {
1016
  template<class T2> class B {
1017
  void mf();
 
1033
  *template-parameter-list* shall be provided instead of the `template<>`
1034
  preceding the explicit specialization declaration of the member. The
1035
  types of the *template-parameter*s in the *template-parameter-list*
1036
  shall be the same as those specified in the primary template definition.
1037
 
1038
+ [*Example 9*:
1039
 
1040
  ``` cpp
1041
  template <class T1> class A {
1042
  template<class T2> class B {
1043
  template<class T3> void mf1(T3);
 
1069
 
1070
  - the explicit specialization of a function template;
1071
  - the explicit specialization of a member function template;
1072
  - the explicit specialization of a member function of a class template
1073
  where the class template specialization to which the member function
1074
+ specialization belongs is implicitly instantiated. \[*Note 5*: Default
1075
  function arguments can be specified in the declaration or definition
1076
  of a member function of a class template specialization that is
1077
  explicitly specialized. — *end note*]
1078