tmp/tmpnsoz_b4r/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Non-member functions <a id="any.nonmembers">[[any.nonmembers]]</a>
|
| 2 |
+
|
| 3 |
+
``` cpp
|
| 4 |
+
void swap(any& x, any& y) noexcept;
|
| 5 |
+
```
|
| 6 |
+
|
| 7 |
+
*Effects:* As if by `x.swap(y)`.
|
| 8 |
+
|
| 9 |
+
``` cpp
|
| 10 |
+
template <class T, class... Args>
|
| 11 |
+
any make_any(Args&& ...args);
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
*Effects:* Equivalent to:
|
| 15 |
+
`return any(in_place_type<T>, std::forward<Args>(args)...);`
|
| 16 |
+
|
| 17 |
+
``` cpp
|
| 18 |
+
template <class T, class U, class... Args>
|
| 19 |
+
any make_any(initializer_list<U> il, Args&& ...args);
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
*Effects:* Equivalent to:
|
| 23 |
+
`return any(in_place_type<T>, il, std::forward<Args>(args)...);`
|
| 24 |
+
|
| 25 |
+
``` cpp
|
| 26 |
+
template<class T>
|
| 27 |
+
T any_cast(const any& operand);
|
| 28 |
+
template<class T>
|
| 29 |
+
T any_cast(any& operand);
|
| 30 |
+
template<class T>
|
| 31 |
+
T any_cast(any&& operand);
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
Let `U` be the type `remove_cv_t<remove_reference_t<ValueType>>`.
|
| 35 |
+
|
| 36 |
+
*Requires:* For the first overload,
|
| 37 |
+
`is_constructible_v<ValueType, const U&>` is `true`. For the second
|
| 38 |
+
overload, `is_constructible_v<ValueType, U&>` is `true`. For the third
|
| 39 |
+
overload, `is_constructible_v<ValueType, U>` is `true`. Otherwise the
|
| 40 |
+
program is ill-formed.
|
| 41 |
+
|
| 42 |
+
*Returns:* For the first and second overload,
|
| 43 |
+
`static_cast<ValueType>(*any_cast<U>(&operand))`. For the third
|
| 44 |
+
overload, `static_cast<ValueType>(std::move(*any_cast<U>(&operand)))`.
|
| 45 |
+
|
| 46 |
+
*Throws:* `bad_any_cast` if
|
| 47 |
+
`operand.type() != typeid(remove_reference_t<T>)`.
|
| 48 |
+
|
| 49 |
+
[*Example 1*:
|
| 50 |
+
|
| 51 |
+
``` cpp
|
| 52 |
+
any x(5); // x holds int
|
| 53 |
+
assert(any_cast<int>(x) == 5); // cast to value
|
| 54 |
+
any_cast<int&>(x) = 10; // cast to reference
|
| 55 |
+
assert(any_cast<int>(x) == 10);
|
| 56 |
+
|
| 57 |
+
x = "Meow"; // x holds const char*
|
| 58 |
+
assert(strcmp(any_cast<const char*>(x), "Meow") == 0);
|
| 59 |
+
any_cast<const char*&>(x) = "Harry";
|
| 60 |
+
assert(strcmp(any_cast<const char*>(x), "Harry") == 0);
|
| 61 |
+
|
| 62 |
+
x = string("Meow"); // x holds string
|
| 63 |
+
string s, s2("Jane");
|
| 64 |
+
s = move(any_cast<string&>(x)); // move from any
|
| 65 |
+
assert(s == "Meow");
|
| 66 |
+
any_cast<string&>(x) = move(s2); // move to any
|
| 67 |
+
assert(any_cast<const string&>(x) == "Jane");
|
| 68 |
+
|
| 69 |
+
string cat("Meow");
|
| 70 |
+
const any y(cat); // const y holds string
|
| 71 |
+
assert(any_cast<const string&>(y) == cat);
|
| 72 |
+
|
| 73 |
+
any_cast<string&>(y); // error; cannot
|
| 74 |
+
// any_cast away const
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
— *end example*]
|
| 78 |
+
|
| 79 |
+
``` cpp
|
| 80 |
+
template<class T>
|
| 81 |
+
const T* any_cast(const any* operand) noexcept;
|
| 82 |
+
template<class T>
|
| 83 |
+
T* any_cast(any* operand) noexcept;
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
*Returns:* If `operand != nullptr && operand->type() == typeid(T)`, a
|
| 87 |
+
pointer to the object contained by `operand`; otherwise, `nullptr`.
|
| 88 |
+
|
| 89 |
+
[*Example 2*:
|
| 90 |
+
|
| 91 |
+
``` cpp
|
| 92 |
+
bool is_string(const any& operand) {
|
| 93 |
+
return any_cast<string>(&operand) != nullptr;
|
| 94 |
+
}
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
— *end example*]
|
| 98 |
+
|