From Jason Turner

[over.match.class.deduct]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpgrzy52yb/{from.md → to.md} +73 -0
tmp/tmpgrzy52yb/{from.md → to.md} RENAMED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template argument deduction <a id="over.match.class.deduct">[[over.match.class.deduct]]</a>
2
+
3
+ A set of functions and function templates is formed comprising:
4
+
5
+ - For each constructor of the primary class template designated by the
6
+ *template-name*, if the template is defined, a function template with
7
+ the following properties:
8
+ - The template parameters are the template parameters of the class
9
+ template followed by the template parameters (including default
10
+ template arguments) of the constructor, if any.
11
+ - The types of the function parameters are those of the constructor.
12
+ - The return type is the class template specialization designated by
13
+ the *template-name* and template arguments corresponding to the
14
+ template parameters obtained from the class template.
15
+ - If the primary class template `C` is not defined or does not declare
16
+ any constructors, an additional function template derived as above
17
+ from a hypothetical constructor `C()`.
18
+ - An additional function template derived as above from a hypothetical
19
+ constructor `C(C)`, called the *copy deduction candidate*.
20
+ - For each *deduction-guide*, a function or function template with the
21
+ following properties:
22
+ - The template parameters, if any, and function parameters are those
23
+ of the *deduction-guide*.
24
+ - The return type is the *simple-template-id* of the
25
+ *deduction-guide*.
26
+
27
+ Initialization and overload resolution are performed as described in
28
+ [[dcl.init]] and [[over.match.ctor]], [[over.match.copy]], or
29
+ [[over.match.list]] (as appropriate for the type of initialization
30
+ performed) for an object of a hypothetical class type, where the
31
+ selected functions and function templates are considered to be the
32
+ constructors of that class type for the purpose of forming an overload
33
+ set, and the initializer is provided by the context in which class
34
+ template argument deduction was performed. Each such notional
35
+ constructor is considered to be explicit if the function or function
36
+ template was generated from a constructor or *deduction-guide* that was
37
+ declared `explicit`. All such notional constructors are considered to be
38
+ public members of the hypothetical class type.
39
+
40
+ [*Example 1*:
41
+
42
+ ``` cpp
43
+ template <class T> struct A {
44
+ explicit A(const T&, ...) noexcept; // #1
45
+ A(T&&, ...); // #2
46
+ };
47
+
48
+ int i;
49
+ A a1 = { i, i }; // error: explicit constructor #1 selected in copy-list-initialization during deduction,
50
+ // cannot deduce from non-forwarding rvalue reference in #2
51
+
52
+ A a2{i, i}; // OK, #1 deduces to A<int> and also initializes
53
+ A a3{0, i}; // OK, #2 deduces to A<int> and also initializes
54
+ A a4 = {0, i}; // OK, #2 deduces to A<int> and also initializes
55
+
56
+ template <class T> A(const T&, const T&) -> A<T&>; // #3
57
+ template <class T> explicit A(T&&, T&&) -> A<T>; // #4
58
+
59
+ A a5 = {0, 1}; // error: explicit deduction guide #4 selected in copy-list-initialization during deduction
60
+ A a6{0,1}; // OK, #4 deduces to A<int> and #2 initializes
61
+ A a7 = {0, i}; // error: #3 deduces to A<int&>, #1 and #2 declare same constructor
62
+ A a8{0,i}; // error: #3 deduces to A<int&>, #1 and #2 declare same constructor
63
+
64
+ template <class T> struct B {
65
+ template <class U> using TA = T;
66
+ template <class U> B(U, TA<U>);
67
+ };
68
+
69
+ B b{(int*)0, (char*)0}; // OK, deduces B<char*>
70
+ ```
71
+
72
+ — *end example*]
73
+