From Jason Turner

[any]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp73vpchv1/{from.md → to.md} +71 -79
tmp/tmp73vpchv1/{from.md → to.md} RENAMED
@@ -1,22 +1,22 @@
1
  ## Storage for any type <a id="any">[[any]]</a>
2
 
3
- This section describes components that C++programs may use to perform
4
  operations on objects of a discriminated type.
5
 
6
  [*Note 1*: The discriminated type may contain values of different types
7
- but does not attempt conversion between them, i.e. `5` is held strictly
8
  as an `int` and is not implicitly convertible either to `"5"` or to
9
  `5.0`. This indifference to interpretation but awareness of type
10
  effectively allows safe, generic containers of single values, with no
11
  scope for surprises from ambiguous conversions. — *end note*]
12
 
13
  ### Header `<any>` synopsis <a id="any.synop">[[any.synop]]</a>
14
 
15
  ``` cpp
16
  namespace std {
17
- // [any.bad_any_cast], class bad_any_cast
18
  class bad_any_cast;
19
 
20
  // [any.class], class any
21
  class any;
22
 
@@ -40,44 +40,43 @@ namespace std {
40
  template<class T>
41
  T* any_cast(any* operand) noexcept;
42
  }
43
  ```
44
 
45
- ### Class `bad_any_cast` <a id="any.bad_any_cast">[[any.bad_any_cast]]</a>
46
 
47
  ``` cpp
48
  class bad_any_cast : public bad_cast {
49
  public:
 
50
  const char* what() const noexcept override;
51
  };
52
  ```
53
 
54
- Objects of type `bad_any_cast` are thrown by a failed `any_cast` (
55
- [[any.nonmembers]]).
56
 
57
  ``` cpp
58
  const char* what() const noexcept override;
59
  ```
60
 
61
  *Returns:* An *implementation-defined* NTBS.
62
 
63
- *Remarks:* The message may be a null-terminated multibyte
64
- string ([[multibyte.strings]]), suitable for conversion and display as
65
- a wstring ([[string.classes]], [[locale.codecvt]]).
66
-
67
  ### Class `any` <a id="any.class">[[any.class]]</a>
68
 
69
  ``` cpp
 
70
  class any {
71
  public:
72
  // [any.cons], construction and destruction
73
  constexpr any() noexcept;
74
 
75
  any(const any& other);
76
  any(any&& other) noexcept;
77
 
78
- template <class T> any(T&& value);
 
79
 
80
  template<class T, class... Args>
81
  explicit any(in_place_type_t<T>, Args&&...);
82
  template<class T, class U, class... Args>
83
  explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
@@ -86,11 +85,12 @@ public:
86
 
87
  // [any.assign], assignments
88
  any& operator=(const any& rhs);
89
  any& operator=(any&& rhs) noexcept;
90
 
91
- template <class T> any& operator=(T&& rhs);
 
92
 
93
  // [any.modifiers], modifiers
94
  template<class T, class... Args>
95
  decay_t<T>& emplace(Args&&...);
96
  template<class T, class U, class... Args>
@@ -100,124 +100,119 @@ public:
100
 
101
  // [any.observers], observers
102
  bool has_value() const noexcept;
103
  const type_info& type() const noexcept;
104
  };
 
105
  ```
106
 
107
- An object of class `any` stores an instance of any type that satisfies
108
- the constructor requirements or it has no value, and this is referred to
109
- as the *state* of the class `any` object. The stored instance is called
110
- the *contained value*, Two states are equivalent if either they both
111
- have no value, or both have a value and the contained values are
112
  equivalent.
113
 
114
  The non-member `any_cast` functions provide type-safe access to the
115
  contained value.
116
 
117
  Implementations should avoid the use of dynamically allocated memory for
118
- a small contained value.
 
 
119
 
120
- [*Example 1*: where the object constructed is holding only an
121
- `int`. — *end example*]
122
-
123
- Such small-object optimization shall only be applied to types `T` for
124
- which `is_nothrow_move_constructible_v<T>` is `true`.
125
 
126
  #### Construction and destruction <a id="any.cons">[[any.cons]]</a>
127
 
128
  ``` cpp
129
  constexpr any() noexcept;
130
  ```
131
 
132
- *Postconditions:* `has_value()` is `false`.
133
 
134
  ``` cpp
135
  any(const any& other);
136
  ```
137
 
138
  *Effects:* If `other.has_value()` is `false`, constructs an object that
139
  has no value. Otherwise, equivalent to
140
- `any(in_place<T>, any_cast<const T&>(other))` where `T` is the type of
141
- the contained object.
142
 
143
  *Throws:* Any exceptions arising from calling the selected constructor
144
  for the contained value.
145
 
146
  ``` cpp
147
  any(any&& other) noexcept;
148
  ```
149
 
150
  *Effects:* If `other.has_value()` is `false`, constructs an object that
151
  has no value. Otherwise, constructs an object of type `any` that
152
- contains either the contained object of `other`, or contains an object
153
- of the same type constructed from the contained object of `other`
154
- considering that contained object as an rvalue.
155
-
156
- *Postconditions:* `other` is left in a valid but otherwise unspecified
157
- state.
158
 
159
  ``` cpp
160
  template<class T>
161
  any(T&& value);
162
  ```
163
 
164
  Let `VT` be `decay_t<T>`.
165
 
166
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
 
167
 
168
  *Effects:* Constructs an object of type `any` that contains an object of
169
  type `VT` direct-initialized with `std::forward<T>(value)`.
170
 
171
- *Remarks:* This constructor shall not participate in overload resolution
172
- unless `VT` is not the same type as `any`, `VT` is not a specialization
173
- of `in_place_type_t`, and `is_copy_constructible_v<VT>` is `true`.
174
-
175
  *Throws:* Any exception thrown by the selected constructor of `VT`.
176
 
177
  ``` cpp
178
  template<class T, class... Args>
179
  explicit any(in_place_type_t<T>, Args&&... args);
180
  ```
181
 
182
  Let `VT` be `decay_t<T>`.
183
 
184
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
185
 
186
  *Effects:* Initializes the contained value as if
187
  direct-non-list-initializing an object of type `VT` with the arguments
188
  `std::forward<Args>(args)...`.
189
 
190
- *Postconditions:* `*this` contains a value of type `VT`.
191
 
192
  *Throws:* Any exception thrown by the selected constructor of `VT`.
193
 
194
- *Remarks:* This constructor shall not participate in overload resolution
195
- unless `is_copy_constructible_v<VT>` is `true` and
196
- `is_constructible_v<VT, Args...>` is `true`.
197
-
198
  ``` cpp
199
  template<class T, class U, class... Args>
200
  explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
201
  ```
202
 
203
  Let `VT` be `decay_t<T>`.
204
 
205
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
206
 
207
  *Effects:* Initializes the contained value as if
208
  direct-non-list-initializing an object of type `VT` with the arguments
209
  `il, std::forward<Args>(args)...`.
210
 
211
- *Postconditions:* `*this` contains a value.
212
 
213
  *Throws:* Any exception thrown by the selected constructor of `VT`.
214
 
215
- *Remarks:* This constructor shall not participate in overload resolution
216
- unless `is_copy_constructible_v<VT>` is `true` and
217
- `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
218
-
219
  ``` cpp
220
  ~any();
221
  ```
222
 
223
  *Effects:* As if by `reset()`.
@@ -242,33 +237,31 @@ any& operator=(any&& rhs) noexcept;
242
 
243
  *Effects:* As if by `any(std::move(rhs)).swap(*this)`.
244
 
245
  *Returns:* `*this`.
246
 
247
- *Postconditions:* The state of `*this` is equivalent to the original
248
- state of `rhs` and `rhs` is left in a valid but otherwise unspecified
249
- state.
250
 
251
  ``` cpp
252
  template<class T>
253
  any& operator=(T&& rhs);
254
  ```
255
 
256
  Let `VT` be `decay_t<T>`.
257
 
258
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
259
 
260
  *Effects:* Constructs an object `tmp` of type `any` that contains an
261
  object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
262
  `tmp.swap(*this)`. No effects if an exception is thrown.
263
 
264
  *Returns:* `*this`.
265
 
266
- *Remarks:* This operator shall not participate in overload resolution
267
- unless `VT` is not the same type as `any` and
268
- `is_copy_constructible_v<VT>` is `true`.
269
-
270
  *Throws:* Any exception thrown by the selected constructor of `VT`.
271
 
272
  #### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
273
 
274
  ``` cpp
@@ -276,60 +269,62 @@ template <class T, class... Args>
276
  decay_t<T>& emplace(Args&&... args);
277
  ```
278
 
279
  Let `VT` be `decay_t<T>`.
280
 
281
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
282
 
283
  *Effects:* Calls `reset()`. Then initializes the contained value as if
284
  direct-non-list-initializing an object of type `VT` with the arguments
285
  `std::forward<Args>(args)...`.
286
 
287
- *Postconditions:* `*this` contains a value.
288
 
289
  *Returns:* A reference to the new contained value.
290
 
291
  *Throws:* Any exception thrown by the selected constructor of `VT`.
292
 
293
  *Remarks:* If an exception is thrown during the call to `VT`’s
294
  constructor, `*this` does not contain a value, and any previously
295
- contained value has been destroyed. This function shall not participate
296
- in overload resolution unless `is_copy_constructible_v<VT>` is `true`
297
- and `is_constructible_v<VT, Args...>` is `true`.
298
 
299
  ``` cpp
300
  template<class T, class U, class... Args>
301
  decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
302
  ```
303
 
304
  Let `VT` be `decay_t<T>`.
305
 
306
- *Requires:* `VT` shall satisfy the `CopyConstructible` requirements.
 
 
 
307
 
308
  *Effects:* Calls `reset()`. Then initializes the contained value as if
309
  direct-non-list-initializing an object of type `VT` with the arguments
310
  `il, std::forward<Args>(args)...`.
311
 
312
- *Postconditions:* `*this` contains a value.
313
 
314
  *Returns:* A reference to the new contained value.
315
 
316
  *Throws:* Any exception thrown by the selected constructor of `VT`.
317
 
318
  *Remarks:* If an exception is thrown during the call to `VT`’s
319
  constructor, `*this` does not contain a value, and any previously
320
- contained value has been destroyed. The function shall not participate
321
- in overload resolution unless `is_copy_constructible_v<VT>` is `true`
322
- and `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
323
 
324
  ``` cpp
325
  void reset() noexcept;
326
  ```
327
 
328
  *Effects:* If `has_value()` is `true`, destroys the contained value.
329
 
330
- *Postconditions:* `has_value()` is `false`.
331
 
332
  ``` cpp
333
  void swap(any& rhs) noexcept;
334
  ```
335
 
@@ -357,11 +352,11 @@ time or only at runtime. — *end note*]
357
 
358
  ``` cpp
359
  void swap(any& x, any& y) noexcept;
360
  ```
361
 
362
- *Effects:* As if by `x.swap(y)`.
363
 
364
  ``` cpp
365
  template<class T, class... Args>
366
  any make_any(Args&&... args);
367
  ```
@@ -384,21 +379,19 @@ template<class T>
384
  T any_cast(any& operand);
385
  template<class T>
386
  T any_cast(any&& operand);
387
  ```
388
 
389
- Let `U` be the type `remove_cv_t<remove_reference_t<ValueType>>`.
390
 
391
- *Requires:* For the first overload,
392
- `is_constructible_v<ValueType, const U&>` is `true`. For the second
393
- overload, `is_constructible_v<ValueType, U&>` is `true`. For the third
394
- overload, `is_constructible_v<ValueType, U>` is `true`. Otherwise the
395
- program is ill-formed.
396
 
397
  *Returns:* For the first and second overload,
398
- `static_cast<ValueType>(*any_cast<U>(&operand))`. For the third
399
- overload, `static_cast<ValueType>(std::move(*any_cast<U>(&operand)))`.
400
 
401
  *Throws:* `bad_any_cast` if
402
  `operand.type() != typeid(remove_reference_t<T>)`.
403
 
404
  [*Example 1*:
@@ -423,12 +416,11 @@ assert(any_cast<const string&>(x) == "Jane");
423
 
424
  string cat("Meow");
425
  const any y(cat); // const y holds string
426
  assert(any_cast<const string&>(y) == cat);
427
 
428
- any_cast<string&>(y); // error; cannot
429
- // any_cast away const
430
  ```
431
 
432
  — *end example*]
433
 
434
  ``` cpp
 
1
  ## Storage for any type <a id="any">[[any]]</a>
2
 
3
+ This subclause describes components that C++ programs may use to perform
4
  operations on objects of a discriminated type.
5
 
6
  [*Note 1*: The discriminated type may contain values of different types
7
+ but does not attempt conversion between them, i.e., `5` is held strictly
8
  as an `int` and is not implicitly convertible either to `"5"` or to
9
  `5.0`. This indifference to interpretation but awareness of type
10
  effectively allows safe, generic containers of single values, with no
11
  scope for surprises from ambiguous conversions. — *end note*]
12
 
13
  ### Header `<any>` synopsis <a id="any.synop">[[any.synop]]</a>
14
 
15
  ``` cpp
16
  namespace std {
17
+ // [any.bad.any.cast], class bad_any_cast
18
  class bad_any_cast;
19
 
20
  // [any.class], class any
21
  class any;
22
 
 
40
  template<class T>
41
  T* any_cast(any* operand) noexcept;
42
  }
43
  ```
44
 
45
+ ### Class `bad_any_cast` <a id="any.bad.any.cast">[[any.bad.any.cast]]</a>
46
 
47
  ``` cpp
48
  class bad_any_cast : public bad_cast {
49
  public:
50
+ // see [exception] for the specification of the special member functions
51
  const char* what() const noexcept override;
52
  };
53
  ```
54
 
55
+ Objects of type `bad_any_cast` are thrown by a failed `any_cast`
56
+ [[any.nonmembers]].
57
 
58
  ``` cpp
59
  const char* what() const noexcept override;
60
  ```
61
 
62
  *Returns:* An *implementation-defined* NTBS.
63
 
 
 
 
 
64
  ### Class `any` <a id="any.class">[[any.class]]</a>
65
 
66
  ``` cpp
67
+ namespace std {
68
  class any {
69
  public:
70
  // [any.cons], construction and destruction
71
  constexpr any() noexcept;
72
 
73
  any(const any& other);
74
  any(any&& other) noexcept;
75
 
76
+ template<class T>
77
+ any(T&& value);
78
 
79
  template<class T, class... Args>
80
  explicit any(in_place_type_t<T>, Args&&...);
81
  template<class T, class U, class... Args>
82
  explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
 
85
 
86
  // [any.assign], assignments
87
  any& operator=(const any& rhs);
88
  any& operator=(any&& rhs) noexcept;
89
 
90
+ template<class T>
91
+ any& operator=(T&& rhs);
92
 
93
  // [any.modifiers], modifiers
94
  template<class T, class... Args>
95
  decay_t<T>& emplace(Args&&...);
96
  template<class T, class U, class... Args>
 
100
 
101
  // [any.observers], observers
102
  bool has_value() const noexcept;
103
  const type_info& type() const noexcept;
104
  };
105
+ }
106
  ```
107
 
108
+ An object of class `any` stores an instance of any type that meets the
109
+ constructor requirements or it has no value, and this is referred to as
110
+ the *state* of the class `any` object. The stored instance is called the
111
+ *contained value*. Two states are equivalent if either they both have no
112
+ value, or they both have a value and the contained values are
113
  equivalent.
114
 
115
  The non-member `any_cast` functions provide type-safe access to the
116
  contained value.
117
 
118
  Implementations should avoid the use of dynamically allocated memory for
119
+ a small contained value. However, any such small-object optimization
120
+ shall only be applied to types `T` for which
121
+ `is_nothrow_move_constructible_v<T>` is `true`.
122
 
123
+ [*Example 1*: A contained value of type `int` could be stored in an
124
+ internal buffer, not in separately-allocated memory. — *end example*]
 
 
 
125
 
126
  #### Construction and destruction <a id="any.cons">[[any.cons]]</a>
127
 
128
  ``` cpp
129
  constexpr any() noexcept;
130
  ```
131
 
132
+ *Ensures:* `has_value()` is `false`.
133
 
134
  ``` cpp
135
  any(const any& other);
136
  ```
137
 
138
  *Effects:* If `other.has_value()` is `false`, constructs an object that
139
  has no value. Otherwise, equivalent to
140
+ `any(in_place_type<T>, any_cast<const T&>(other))` where `T` is the type
141
+ of the contained value.
142
 
143
  *Throws:* Any exceptions arising from calling the selected constructor
144
  for the contained value.
145
 
146
  ``` cpp
147
  any(any&& other) noexcept;
148
  ```
149
 
150
  *Effects:* If `other.has_value()` is `false`, constructs an object that
151
  has no value. Otherwise, constructs an object of type `any` that
152
+ contains either the contained value of `other`, or contains an object of
153
+ the same type constructed from the contained value of `other`
154
+ considering that contained value as an rvalue.
 
 
 
155
 
156
  ``` cpp
157
  template<class T>
158
  any(T&& value);
159
  ```
160
 
161
  Let `VT` be `decay_t<T>`.
162
 
163
+ *Constraints:* `VT` is not the same type as `any`, `VT` is not a
164
+ specialization of `in_place_type_t`, and `is_copy_constructible_v<VT>`
165
+ is `true`.
166
+
167
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
168
 
169
  *Effects:* Constructs an object of type `any` that contains an object of
170
  type `VT` direct-initialized with `std::forward<T>(value)`.
171
 
 
 
 
 
172
  *Throws:* Any exception thrown by the selected constructor of `VT`.
173
 
174
  ``` cpp
175
  template<class T, class... Args>
176
  explicit any(in_place_type_t<T>, Args&&... args);
177
  ```
178
 
179
  Let `VT` be `decay_t<T>`.
180
 
181
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
182
+ `is_constructible_v<VT, Args...>` is `true`.
183
+
184
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
185
 
186
  *Effects:* Initializes the contained value as if
187
  direct-non-list-initializing an object of type `VT` with the arguments
188
  `std::forward<Args>(args)...`.
189
 
190
+ *Ensures:* `*this` contains a value of type `VT`.
191
 
192
  *Throws:* Any exception thrown by the selected constructor of `VT`.
193
 
 
 
 
 
194
  ``` cpp
195
  template<class T, class U, class... Args>
196
  explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
197
  ```
198
 
199
  Let `VT` be `decay_t<T>`.
200
 
201
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
202
+ `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
203
+
204
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
205
 
206
  *Effects:* Initializes the contained value as if
207
  direct-non-list-initializing an object of type `VT` with the arguments
208
  `il, std::forward<Args>(args)...`.
209
 
210
+ *Ensures:* `*this` contains a value.
211
 
212
  *Throws:* Any exception thrown by the selected constructor of `VT`.
213
 
 
 
 
 
214
  ``` cpp
215
  ~any();
216
  ```
217
 
218
  *Effects:* As if by `reset()`.
 
237
 
238
  *Effects:* As if by `any(std::move(rhs)).swap(*this)`.
239
 
240
  *Returns:* `*this`.
241
 
242
+ *Ensures:* The state of `*this` is equivalent to the original state of
243
+ `rhs`.
 
244
 
245
  ``` cpp
246
  template<class T>
247
  any& operator=(T&& rhs);
248
  ```
249
 
250
  Let `VT` be `decay_t<T>`.
251
 
252
+ *Constraints:* `VT` is not the same type as `any` and
253
+ `is_copy_constructible_v<VT>` is `true`.
254
+
255
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
256
 
257
  *Effects:* Constructs an object `tmp` of type `any` that contains an
258
  object of type `VT` direct-initialized with `std::forward<T>(rhs)`, and
259
  `tmp.swap(*this)`. No effects if an exception is thrown.
260
 
261
  *Returns:* `*this`.
262
 
 
 
 
 
263
  *Throws:* Any exception thrown by the selected constructor of `VT`.
264
 
265
  #### Modifiers <a id="any.modifiers">[[any.modifiers]]</a>
266
 
267
  ``` cpp
 
269
  decay_t<T>& emplace(Args&&... args);
270
  ```
271
 
272
  Let `VT` be `decay_t<T>`.
273
 
274
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
275
+ `is_constructible_v<VT, Args...>` is `true`.
276
+
277
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
278
 
279
  *Effects:* Calls `reset()`. Then initializes the contained value as if
280
  direct-non-list-initializing an object of type `VT` with the arguments
281
  `std::forward<Args>(args)...`.
282
 
283
+ *Ensures:* `*this` contains a value.
284
 
285
  *Returns:* A reference to the new contained value.
286
 
287
  *Throws:* Any exception thrown by the selected constructor of `VT`.
288
 
289
  *Remarks:* If an exception is thrown during the call to `VT`’s
290
  constructor, `*this` does not contain a value, and any previously
291
+ contained value has been destroyed.
 
 
292
 
293
  ``` cpp
294
  template<class T, class U, class... Args>
295
  decay_t<T>& emplace(initializer_list<U> il, Args&&... args);
296
  ```
297
 
298
  Let `VT` be `decay_t<T>`.
299
 
300
+ *Constraints:* `is_copy_constructible_v<VT>` is `true` and
301
+ `is_constructible_v<VT, initializer_list<U>&, Args...>` is `true`.
302
+
303
+ *Preconditions:* `VT` meets the *Cpp17CopyConstructible* requirements.
304
 
305
  *Effects:* Calls `reset()`. Then initializes the contained value as if
306
  direct-non-list-initializing an object of type `VT` with the arguments
307
  `il, std::forward<Args>(args)...`.
308
 
309
+ *Ensures:* `*this` contains a value.
310
 
311
  *Returns:* A reference to the new contained value.
312
 
313
  *Throws:* Any exception thrown by the selected constructor of `VT`.
314
 
315
  *Remarks:* If an exception is thrown during the call to `VT`’s
316
  constructor, `*this` does not contain a value, and any previously
317
+ contained value has been destroyed.
 
 
318
 
319
  ``` cpp
320
  void reset() noexcept;
321
  ```
322
 
323
  *Effects:* If `has_value()` is `true`, destroys the contained value.
324
 
325
+ *Ensures:* `has_value()` is `false`.
326
 
327
  ``` cpp
328
  void swap(any& rhs) noexcept;
329
  ```
330
 
 
352
 
353
  ``` cpp
354
  void swap(any& x, any& y) noexcept;
355
  ```
356
 
357
+ *Effects:* Equivalent to `x.swap(y)`.
358
 
359
  ``` cpp
360
  template<class T, class... Args>
361
  any make_any(Args&&... args);
362
  ```
 
379
  T any_cast(any& operand);
380
  template<class T>
381
  T any_cast(any&& operand);
382
  ```
383
 
384
+ Let `U` be the type `remove_cvref_t<T>`.
385
 
386
+ *Mandates:* For the first overload, `is_constructible_v<T, const U&>` is
387
+ `true`. For the second overload, `is_constructible_v<T, U&>` is `true`.
388
+ For the third overload, `is_constructible_v<T, U>` is `true`.
 
 
389
 
390
  *Returns:* For the first and second overload,
391
+ `static_cast<T>(*any_cast<U>(&operand))`. For the third overload,
392
+ `static_cast<T>(std::move(*any_cast<U>(&operand)))`.
393
 
394
  *Throws:* `bad_any_cast` if
395
  `operand.type() != typeid(remove_reference_t<T>)`.
396
 
397
  [*Example 1*:
 
416
 
417
  string cat("Meow");
418
  const any y(cat); // const y holds string
419
  assert(any_cast<const string&>(y) == cat);
420
 
421
+ any_cast<string&>(y); // error: cannot any_cast away const
 
422
  ```
423
 
424
  — *end example*]
425
 
426
  ``` cpp