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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 23 |
+
// [any.nonmembers], non-member functions
|
| 24 |
+
void swap(any& x, any& y) noexcept;
|
| 25 |
+
|
| 26 |
+
template <class T, class... Args>
|
| 27 |
+
any make_any(Args&& ...args);
|
| 28 |
+
template <class T, class U, class... Args>
|
| 29 |
+
any make_any(initializer_list<U> il, Args&& ...args);
|
| 30 |
+
|
| 31 |
+
template<class T>
|
| 32 |
+
T any_cast(const any& operand);
|
| 33 |
+
template<class T>
|
| 34 |
+
T any_cast(any& operand);
|
| 35 |
+
template<class T>
|
| 36 |
+
T any_cast(any&& operand);
|
| 37 |
+
|
| 38 |
+
template<class T>
|
| 39 |
+
const T* any_cast(const any* operand) noexcept;
|
| 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&&...);
|
| 84 |
+
|
| 85 |
+
~any();
|
| 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>
|
| 97 |
+
decay_t<T>& emplace(initializer_list<U>, Args&&...);
|
| 98 |
+
void reset() noexcept;
|
| 99 |
+
void swap(any& rhs) noexcept;
|
| 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()`.
|
| 224 |
+
|
| 225 |
+
#### Assignment <a id="any.assign">[[any.assign]]</a>
|
| 226 |
+
|
| 227 |
+
``` cpp
|
| 228 |
+
any& operator=(const any& rhs);
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
*Effects:* As if by `any(rhs).swap(*this)`. No effects if an exception
|
| 232 |
+
is thrown.
|
| 233 |
+
|
| 234 |
+
*Returns:* `*this`.
|
| 235 |
+
|
| 236 |
+
*Throws:* Any exceptions arising from the copy constructor for the
|
| 237 |
+
contained value.
|
| 238 |
+
|
| 239 |
+
``` cpp
|
| 240 |
+
any& operator=(any&& rhs) noexcept;
|
| 241 |
+
```
|
| 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
|
| 275 |
+
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 |
+
|
| 336 |
+
*Effects:* Exchanges the states of `*this` and `rhs`.
|
| 337 |
+
|
| 338 |
+
#### Observers <a id="any.observers">[[any.observers]]</a>
|
| 339 |
+
|
| 340 |
+
``` cpp
|
| 341 |
+
bool has_value() const noexcept;
|
| 342 |
+
```
|
| 343 |
+
|
| 344 |
+
*Returns:* `true` if `*this` contains an object, otherwise `false`.
|
| 345 |
+
|
| 346 |
+
``` cpp
|
| 347 |
+
const type_info& type() const noexcept;
|
| 348 |
+
```
|
| 349 |
+
|
| 350 |
+
*Returns:* `typeid(T)` if `*this` has a contained value of type `T`,
|
| 351 |
+
otherwise `typeid(void)`.
|
| 352 |
+
|
| 353 |
+
[*Note 1*: Useful for querying against types known either at compile
|
| 354 |
+
time or only at runtime. — *end note*]
|
| 355 |
+
|
| 356 |
+
### Non-member functions <a id="any.nonmembers">[[any.nonmembers]]</a>
|
| 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 |
+
```
|
| 368 |
+
|
| 369 |
+
*Effects:* Equivalent to:
|
| 370 |
+
`return any(in_place_type<T>, std::forward<Args>(args)...);`
|
| 371 |
+
|
| 372 |
+
``` cpp
|
| 373 |
+
template <class T, class U, class... Args>
|
| 374 |
+
any make_any(initializer_list<U> il, Args&& ...args);
|
| 375 |
+
```
|
| 376 |
+
|
| 377 |
+
*Effects:* Equivalent to:
|
| 378 |
+
`return any(in_place_type<T>, il, std::forward<Args>(args)...);`
|
| 379 |
+
|
| 380 |
+
``` cpp
|
| 381 |
+
template<class T>
|
| 382 |
+
T any_cast(const any& operand);
|
| 383 |
+
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*:
|
| 405 |
+
|
| 406 |
+
``` cpp
|
| 407 |
+
any x(5); // x holds int
|
| 408 |
+
assert(any_cast<int>(x) == 5); // cast to value
|
| 409 |
+
any_cast<int&>(x) = 10; // cast to reference
|
| 410 |
+
assert(any_cast<int>(x) == 10);
|
| 411 |
+
|
| 412 |
+
x = "Meow"; // x holds const char*
|
| 413 |
+
assert(strcmp(any_cast<const char*>(x), "Meow") == 0);
|
| 414 |
+
any_cast<const char*&>(x) = "Harry";
|
| 415 |
+
assert(strcmp(any_cast<const char*>(x), "Harry") == 0);
|
| 416 |
+
|
| 417 |
+
x = string("Meow"); // x holds string
|
| 418 |
+
string s, s2("Jane");
|
| 419 |
+
s = move(any_cast<string&>(x)); // move from any
|
| 420 |
+
assert(s == "Meow");
|
| 421 |
+
any_cast<string&>(x) = move(s2); // move to any
|
| 422 |
+
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
|
| 435 |
+
template<class T>
|
| 436 |
+
const T* any_cast(const any* operand) noexcept;
|
| 437 |
+
template<class T>
|
| 438 |
+
T* any_cast(any* operand) noexcept;
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
*Returns:* If `operand != nullptr && operand->type() == typeid(T)`, a
|
| 442 |
+
pointer to the object contained by `operand`; otherwise, `nullptr`.
|
| 443 |
+
|
| 444 |
+
[*Example 2*:
|
| 445 |
+
|
| 446 |
+
``` cpp
|
| 447 |
+
bool is_string(const any& operand) {
|
| 448 |
+
return any_cast<string>(&operand) != nullptr;
|
| 449 |
+
}
|
| 450 |
+
```
|
| 451 |
+
|
| 452 |
+
— *end example*]
|
| 453 |
+
|