From Jason Turner

[any.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplup38jip/{from.md → to.md} +289 -0
tmp/tmplup38jip/{from.md → to.md} RENAMED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class `any` <a id="any.class">[[any.class]]</a>
2
+
3
+ ``` cpp
4
+ class any {
5
+ public:
6
+ // [any.cons], construction and destruction
7
+ constexpr any() noexcept;
8
+
9
+ any(const any& other);
10
+ any(any&& other) noexcept;
11
+
12
+ template <class T> any(T&& value);
13
+
14
+ template <class T, class... Args>
15
+ explicit any(in_place_type_t<T>, Args&&...);
16
+ template <class T, class U, class... Args>
17
+ explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
18
+
19
+ ~any();
20
+
21
+ // [any.assign], assignments
22
+ any& operator=(const any& rhs);
23
+ any& operator=(any&& rhs) noexcept;
24
+
25
+ template <class T> any& operator=(T&& rhs);
26
+
27
+ // [any.modifiers], modifiers
28
+ template <class T, class... Args>
29
+ decay_t<T>& emplace(Args&& ...);
30
+ template <class T, class U, class... Args>
31
+ decay_t<T>& emplace(initializer_list<U>, Args&&...);
32
+ void reset() noexcept;
33
+ void swap(any& rhs) noexcept;
34
+
35
+ // [any.observers], observers
36
+ bool has_value() const noexcept;
37
+ const type_info& type() const noexcept;
38
+ };
39
+ ```
40
+
41
+ An object of class `any` stores an instance of any type that satisfies
42
+ the constructor requirements or it has no value, and this is referred to
43
+ as the *state* of the class `any` object. The stored instance is called
44
+ the *contained value*, Two states are equivalent if either they both
45
+ have no value, or both have a value and the contained values are
46
+ equivalent.
47
+
48
+ The non-member `any_cast` functions provide type-safe access to the
49
+ contained value.
50
+
51
+ Implementations should avoid the use of dynamically allocated memory for
52
+ a small contained value.
53
+
54
+ [*Example 1*: where the object constructed is holding only an
55
+ `int`. — *end example*]
56
+
57
+ Such small-object optimization shall only be applied to types `T` for
58
+ which `is_nothrow_move_constructible_v<T>` is `true`.
59
+
60
+ #### Construction and destruction <a id="any.cons">[[any.cons]]</a>
61
+
62
+ ``` cpp
63
+ constexpr any() noexcept;
64
+ ```
65
+
66
+ *Postconditions:* `has_value()` is `false`.
67
+
68
+ ``` cpp
69
+ any(const any& other);
70
+ ```
71
+
72
+ *Effects:* If `other.has_value()` is `false`, constructs an object that
73
+ has no value. Otherwise, equivalent to
74
+ `any(in_place<T>, any_cast<const T&>(other))` where `T` is the type of
75
+ the contained object.
76
+
77
+ *Throws:* Any exceptions arising from calling the selected constructor
78
+ for the contained value.
79
+
80
+ ``` cpp
81
+ any(any&& other) noexcept;
82
+ ```
83
+
84
+ *Effects:* If `other.has_value()` is `false`, constructs an object that
85
+ has no value. Otherwise, constructs an object of type `any` that
86
+ contains either the contained object of `other`, or contains an object
87
+ of the same type constructed from the contained object of `other`
88
+ considering that contained object as an rvalue.
89
+
90
+ *Postconditions:* `other` is left in a valid but otherwise unspecified
91
+ state.
92
+
93
+ ``` cpp
94
+ template<class T>
95
+ any(T&& value);
96
+ ```
97
+
98
+ Let `VT` be `decay_t<T>`.
99
+
100
+ *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
101
+
102
+ *Effects:* Constructs an object of type `any` that contains an object of
103
+ type `VT` direct-initialized with `std::forward<T>(value)`.
104
+
105
+ *Remarks:* This constructor shall not participate in overload resolution
106
+ unless `VT` is not the same type as `any`, `VT` is not a specialization
107
+ of `in_place_type_t`, and `is_copy_constructible_v<VT>` is `true`.
108
+
109
+ *Throws:* Any exception thrown by the selected constructor of `VT`.
110
+
111
+ ``` cpp
112
+ template <class T, class... Args>
113
+ explicit any(in_place_type_t<T>, Args&&... args);
114
+ ```
115
+
116
+ Let `VT` be `decay_t<T>`.
117
+
118
+ *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
119
+
120
+ *Effects:* Initializes the contained value as if
121
+ direct-non-list-initializing an object of type `VT` with the arguments
122
+ `std::forward<Args>(args)...`.
123
+
124
+ *Postconditions:* `*this` contains a value of type `VT`.
125
+
126
+ *Throws:* Any exception thrown by the selected constructor of `VT`.
127
+
128
+ *Remarks:* This constructor shall not participate in overload resolution
129
+ unless `is_copy_constructible_v<VT>` is `true` and
130
+ `is_constructible_v<VT, Args...>` is `true`.
131
+
132
+ ``` cpp
133
+ template <class T, class U, class... Args>
134
+ explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
135
+ ```
136
+
137
+ Let `VT` be `decay_t<T>`.
138
+
139
+ *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
140
+
141
+ *Effects:* Initializes the contained value as if
142
+ direct-non-list-initializing an object of type `VT` with the arguments
143
+ `il, std::forward<Args>(args)...`.
144
+
145
+ *Postconditions:* `*this` contains a value.
146
+
147
+ *Throws:* Any exception thrown by the selected constructor of `VT`.
148
+
149
+ *Remarks:* This constructor shall not participate in overload resolution
150
+ unless `is_copy_constructible_v<VT>` is `true` and
151
+ `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
152
+
153
+ ``` cpp
154
+ ~any();
155
+ ```
156
+
157
+ *Effects:* As if by `reset()`.
158
+
159
+ #### Assignment <a id="any.assign">[[any.assign]]</a>
160
+
161
+ ``` cpp
162
+ any& operator=(const any& rhs);
163
+ ```
164
+
165
+ *Effects:* As if by `any(rhs).swap(*this)`. No effects if an exception
166
+ is thrown.
167
+
168
+ *Returns:* `*this`.
169
+
170
+ *Throws:* Any exceptions arising from the copy constructor for the
171
+ contained value.
172
+
173
+ ``` cpp
174
+ any& operator=(any&& rhs) noexcept;
175
+ ```
176
+
177
+ *Effects:* As if by `any(std::move(rhs)).swap(*this)`.
178
+
179
+ *Returns:* `*this`.
180
+
181
+ *Postconditions:* The state of `*this` is equivalent to the original
182
+ state of `rhs` and `rhs` is left in a valid but otherwise unspecified
183
+ state.
184
+
185
+ ``` cpp
186
+ template<class T>
187
+ any& operator=(T&& rhs);
188
+ ```
189
+
190
+ Let `VT` be `decay_t<T>`.
191
+
192
+ *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
193
+
194
+ *Effects:* Constructs an object `tmp` of type `any` that contains an
195
+ object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
196
+ `tmp.swap(*this)`. No effects if an exception is thrown.
197
+
198
+ *Returns:* `*this`.
199
+
200
+ *Remarks:* This operator shall not participate in overload resolution
201
+ unless `VT` is not the same type as `any` and
202
+ `is_copy_constructible_v<VT>` is `true`.
203
+
204
+ *Throws:* Any exception thrown by the selected constructor of `VT`.
205
+
206
+ #### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
207
+
208
+ ``` cpp
209
+ template <class T, class... Args>
210
+ decay_t<T>& emplace(Args&&... args);
211
+ ```
212
+
213
+ Let `VT` be `decay_t<T>`.
214
+
215
+ *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
216
+
217
+ *Effects:* Calls `reset()`. Then initializes the contained value as if
218
+ direct-non-list-initializing an object of type `VT` with the arguments
219
+ `std::forward<Args>(args)...`.
220
+
221
+ *Postconditions:* `*this` contains a value.
222
+
223
+ *Returns:* A reference to the new contained value.
224
+
225
+ *Throws:* Any exception thrown by the selected constructor of `VT`.
226
+
227
+ *Remarks:* If an exception is thrown during the call to `VT`’s
228
+ constructor, `*this` does not contain a value, and any previously
229
+ contained value has been destroyed. This function shall not participate
230
+ in overload resolution unless `is_copy_constructible_v<VT>` is `true`
231
+ and `is_constructible_v<VT, Args...>` is `true`.
232
+
233
+ ``` cpp
234
+ template <class T, class U, class... Args>
235
+ decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
236
+ ```
237
+
238
+ Let `VT` be `decay_t<T>`.
239
+
240
+ *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
241
+
242
+ *Effects:* Calls `reset()`. Then initializes the contained value as if
243
+ direct-non-list-initializing an object of type `VT` with the arguments
244
+ `il, std::forward<Args>(args)...`.
245
+
246
+ *Postconditions:* `*this` contains a value.
247
+
248
+ *Returns:* A reference to the new contained value.
249
+
250
+ *Throws:* Any exception thrown by the selected constructor of `VT`.
251
+
252
+ *Remarks:* If an exception is thrown during the call to `VT`’s
253
+ constructor, `*this` does not contain a value, and any previously
254
+ contained value has been destroyed. The function shall not participate
255
+ in overload resolution unless `is_copy_constructible_v<VT>` is `true`
256
+ and `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
257
+
258
+ ``` cpp
259
+ void reset() noexcept;
260
+ ```
261
+
262
+ *Effects:* If `has_value()` is `true`, destroys the contained value.
263
+
264
+ *Postconditions:* `has_value()` is `false`.
265
+
266
+ ``` cpp
267
+ void swap(any& rhs) noexcept;
268
+ ```
269
+
270
+ *Effects:* Exchanges the states of `*this` and `rhs`.
271
+
272
+ #### Observers <a id="any.observers">[[any.observers]]</a>
273
+
274
+ ``` cpp
275
+ bool has_value() const noexcept;
276
+ ```
277
+
278
+ *Returns:* `true` if `*this` contains an object, otherwise `false`.
279
+
280
+ ``` cpp
281
+ const type_info& type() const noexcept;
282
+ ```
283
+
284
+ *Returns:* `typeid(T)` if `*this` has a contained value of type `T`,
285
+ otherwise `typeid(void)`.
286
+
287
+ [*Note 1*: Useful for querying against types known either at compile
288
+ time or only at runtime. — *end note*]
289
+