From Jason Turner

[func.wrap.ref]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp295_0okp/{from.md → to.md} +240 -0
tmp/tmp295_0okp/{from.md → to.md} RENAMED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Non-owning wrapper <a id="func.wrap.ref">[[func.wrap.ref]]</a>
2
+
3
+ ##### General <a id="func.wrap.ref.general">[[func.wrap.ref.general]]</a>
4
+
5
+ The header provides partial specializations of `function_ref` for each
6
+ combination of the possible replacements of the placeholders cv and
7
+ *noex* where:
8
+
9
+ - cv is either const or empty, and
10
+ - *noex* is either `true` or `false`.
11
+
12
+ ##### Class template `function_ref` <a id="func.wrap.ref.class">[[func.wrap.ref.class]]</a>
13
+
14
+ ``` cpp
15
+ namespace std {
16
+ template<class R, class... ArgTypes>
17
+ class function_ref<R(ArgTypes...) cv noexcept(noex)> {
18
+ public:
19
+ // [func.wrap.ref.ctor], constructors and assignment operators
20
+ template<class F> function_ref(F*) noexcept;
21
+ template<class F> constexpr function_ref(F&&) noexcept;
22
+ template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
23
+ template<auto f, class U> constexpr function_ref(nontype_t<f>, U&&) noexcept;
24
+ template<auto f, class T> constexpr function_ref(nontype_t<f>, cv T*) noexcept;
25
+
26
+ constexpr function_ref(const function_ref&) noexcept = default;
27
+ constexpr function_ref& operator=(const function_ref&) noexcept = default;
28
+ template<class T> function_ref& operator=(T) = delete;
29
+
30
+ // [func.wrap.ref.inv], invocation
31
+ R operator()(ArgTypes...) const noexcept(noex);
32
+
33
+ private:
34
+ template<class... T>
35
+ static constexpr bool is-invocable-using = see belownc; // exposition only
36
+
37
+ R (*thunk-ptr)(BoundEntityType, ArgTypes&&...) noexcept(noex); // exposition only
38
+ BoundEntityType bound-entity; // exposition only
39
+ };
40
+
41
+ // [func.wrap.ref.deduct], deduction guides
42
+ template<class F>
43
+ function_ref(F*) -> function_ref<F>;
44
+ template<auto f>
45
+ function_ref(nontype_t<f>) -> function_ref<see below>;
46
+ template<auto f, class T>
47
+ function_ref(nontype_t<f>, T&&) -> function_ref<see below>;
48
+ }
49
+ ```
50
+
51
+ An object of class `function_ref<R(Args...) cv noexcept(noex)>` stores a
52
+ pointer to function *`thunk-ptr`* and an object *`bound-entity`*. The
53
+ object *`bound-entity`* has an unspecified trivially copyable type
54
+ *`BoundEntityType`*, that models `copyable` and is capable of storing a
55
+ pointer to object value or a pointer to function value. The type of
56
+ *`thunk-ptr`* is `R(*)(BoundEntityType, Args&&...) noexcept(noex)`.
57
+
58
+ Each specialization of `function_ref` is a trivially copyable type
59
+ [[term.trivially.copyable.type]] that models `copyable`.
60
+
61
+ Within subclause  [[func.wrap.ref]], `call-args` is an argument pack
62
+ with elements such that
63
+
64
+ ``` cpp
65
+ decltype((call-args))...
66
+ ```
67
+
68
+ denote `ArgTypes&&...` respectively.
69
+
70
+ ##### Constructors and assignment operators <a id="func.wrap.ref.ctor">[[func.wrap.ref.ctor]]</a>
71
+
72
+ ``` cpp
73
+ template<class... T>
74
+ static constexpr bool is-invocable-using = see below;
75
+ ```
76
+
77
+ If *noex* is `true`, *`is-invocable-using`*`<T...>` is equal to:
78
+
79
+ ``` cpp
80
+ is_nothrow_invocable_r_v<R, T..., ArgTypes...>
81
+ ```
82
+
83
+ Otherwise, *`is-invocable-using`*`<T...>` is equal to:
84
+
85
+ ``` cpp
86
+ is_invocable_r_v<R, T..., ArgTypes...>
87
+ ```
88
+
89
+ ``` cpp
90
+ template<class F> function_ref(F* f) noexcept;
91
+ ```
92
+
93
+ *Constraints:*
94
+
95
+ - `is_function_v<F>` is `true`, and
96
+ - *`is-invocable-using`*`<F>` is `true`.
97
+
98
+ *Preconditions:* `f` is not a null pointer.
99
+
100
+ *Effects:* Initializes *bound-entity* with `f`, and *thunk-ptr* with the
101
+ address of a function *`thunk`* such that
102
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
103
+ expression-equivalent [[defns.expression.equivalent]] to
104
+ `invoke_r<R>(f, `*`call-args`*`...)`.
105
+
106
+ ``` cpp
107
+ template<class F> constexpr function_ref(F&& f) noexcept;
108
+ ```
109
+
110
+ Let `T` be `remove_reference_t<F>`.
111
+
112
+ *Constraints:*
113
+
114
+ - `remove_cvref_t<F>` is not the same type as `function_ref`,
115
+ - `is_member_pointer_v<T>` is `false`, and
116
+ - *`is-invocable-using`*`<cv T&>` is `true`.
117
+
118
+ *Effects:* Initializes *bound-entity* with `addressof(f)`, and
119
+ *thunk-ptr* with the address of a function *`thunk`* such that
120
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
121
+ expression-equivalent [[defns.expression.equivalent]] to
122
+ `invoke_r<R>(static_cast<cv T&>(f), `*`call-args`*`...)`.
123
+
124
+ ``` cpp
125
+ template<auto f> constexpr function_ref(nontype_t<f>) noexcept;
126
+ ```
127
+
128
+ Let `F` be `decltype(f)`.
129
+
130
+ *Constraints:* *`is-invocable-using`*`<F>` is `true`.
131
+
132
+ *Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
133
+ then `f != nullptr` is `true`.
134
+
135
+ *Effects:* Initializes *bound-entity* with a pointer to an unspecified
136
+ object or null pointer value, and *thunk-ptr* with the address of a
137
+ function *`thunk`* such that
138
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
139
+ expression-equivalent [[defns.expression.equivalent]] to
140
+ `invoke_r<R>(f, `*`call-args`*`...)`.
141
+
142
+ ``` cpp
143
+ template<auto f, class U>
144
+ constexpr function_ref(nontype_t<f>, U&& obj) noexcept;
145
+ ```
146
+
147
+ Let `T` be `remove_reference_t<U>` and `F` be `decltype(f)`.
148
+
149
+ *Constraints:*
150
+
151
+ - `is_rvalue_reference_v<U&&>` is `false`, and
152
+ - *`is-invocable-using`*`<F, cv T&>` is `true`.
153
+
154
+ *Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
155
+ then `f != nullptr` is `true`.
156
+
157
+ *Effects:* Initializes *bound-entity* with `addressof(obj)`, and
158
+ *thunk-ptr* with the address of a function *`thunk`* such that
159
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
160
+ expression-equivalent [[defns.expression.equivalent]] to
161
+ `invoke_r<R>(f, static_cast<cv T&>(obj), `*`call-args`*`...)`.
162
+
163
+ ``` cpp
164
+ template<auto f, class T>
165
+ constexpr function_ref(nontype_t<f>, cv T* obj) noexcept;
166
+ ```
167
+
168
+ Let `F` be `decltype(f)`.
169
+
170
+ *Constraints:* *`is-invocable-using`*`<F, cv T*>` is `true`.
171
+
172
+ *Mandates:* If `is_pointer_v<F> || is_member_pointer_v<F>` is `true`,
173
+ then `f != nullptr` is `true`.
174
+
175
+ *Preconditions:* If `is_member_pointer_v<F>` is `true`, `obj` is not a
176
+ null pointer.
177
+
178
+ *Effects:* Initializes *bound-entity* with `obj`, and *thunk-ptr* with
179
+ the address of a function *`thunk`* such that
180
+ *`thunk`*`(`*`bound-entity`*`, `*`call-args`*`...)` is
181
+ expression-equivalent [[defns.expression.equivalent]] to
182
+ `invoke_r<R>(f, obj, `*`call-args`*`...)`.
183
+
184
+ ``` cpp
185
+ template<class T> function_ref& operator=(T) = delete;
186
+ ```
187
+
188
+ *Constraints:*
189
+
190
+ - `T` is not the same type as `function_ref`,
191
+ - `is_pointer_v<T>` is `false`, and
192
+ - `T` is not a specialization of `nontype_t`.
193
+
194
+ ##### Invocation <a id="func.wrap.ref.inv">[[func.wrap.ref.inv]]</a>
195
+
196
+ ``` cpp
197
+ R operator()(ArgTypes... args) const noexcept(noex);
198
+ ```
199
+
200
+ *Effects:* Equivalent to:
201
+ `return `*`thunk-ptr`*`(`*`bound-entity`*`, std::forward<ArgTypes>(args)...);`
202
+
203
+ ##### Deduction guides <a id="func.wrap.ref.deduct">[[func.wrap.ref.deduct]]</a>
204
+
205
+ ``` cpp
206
+ template<class F>
207
+ function_ref(F*) -> function_ref<F>;
208
+ ```
209
+
210
+ *Constraints:* `is_function_v<F>` is `true`.
211
+
212
+ ``` cpp
213
+ template<auto f>
214
+ function_ref(nontype_t<f>) -> function_ref<see below>;
215
+ ```
216
+
217
+ Let `F` be `remove_pointer_t<decltype(f)>`.
218
+
219
+ *Constraints:* `is_function_v<F>` is `true`.
220
+
221
+ *Remarks:* The deduced type is `function_ref<F>`.
222
+
223
+ ``` cpp
224
+ template<auto f, class T>
225
+ function_ref(nontype_t<f>, T&&) -> function_ref<see below>;
226
+ ```
227
+
228
+ Let `F` be `decltype(f)`.
229
+
230
+ *Constraints:*
231
+
232
+ - `F` is of the form `R(G::*)(A...) cv `\\ₒₚₜ ` noexcept(E)` for a type
233
+ `G`, or
234
+ - `F` is of the form `M G::*` for a type `G` and an object type `M`, in
235
+ which case let `R` be `invoke_result_t<F, T&>`, `A...` be an empty
236
+ pack, and `E` be `false`, or
237
+ - `F` is of the form `R(*)(G, A...) noexcept(E)` for a type `G`.
238
+
239
+ *Remarks:* The deduced type is `function_ref<R(A...) noexcept(E)>`.
240
+