tmp/tmpt3ur912i/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="optional.optional.general">[[optional.optional.general]]</a>
|
| 2 |
+
|
| 3 |
+
``` cpp
|
| 4 |
+
namespace std {
|
| 5 |
+
template<class T>
|
| 6 |
+
class optional {
|
| 7 |
+
public:
|
| 8 |
+
using value_type = T;
|
| 9 |
+
|
| 10 |
+
// [optional.ctor], constructors
|
| 11 |
+
constexpr optional() noexcept;
|
| 12 |
+
constexpr optional(nullopt_t) noexcept;
|
| 13 |
+
constexpr optional(const optional&);
|
| 14 |
+
constexpr optional(optional&&) noexcept(see below);
|
| 15 |
+
template<class... Args>
|
| 16 |
+
constexpr explicit optional(in_place_t, Args&&...);
|
| 17 |
+
template<class U, class... Args>
|
| 18 |
+
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
| 19 |
+
template<class U = T>
|
| 20 |
+
constexpr explicit(see below) optional(U&&);
|
| 21 |
+
template<class U>
|
| 22 |
+
constexpr explicit(see below) optional(const optional<U>&);
|
| 23 |
+
template<class U>
|
| 24 |
+
constexpr explicit(see below) optional(optional<U>&&);
|
| 25 |
+
|
| 26 |
+
// [optional.dtor], destructor
|
| 27 |
+
constexpr ~optional();
|
| 28 |
+
|
| 29 |
+
// [optional.assign], assignment
|
| 30 |
+
constexpr optional& operator=(nullopt_t) noexcept;
|
| 31 |
+
constexpr optional& operator=(const optional&);
|
| 32 |
+
constexpr optional& operator=(optional&&) noexcept(see below);
|
| 33 |
+
template<class U = T> constexpr optional& operator=(U&&);
|
| 34 |
+
template<class U> constexpr optional& operator=(const optional<U>&);
|
| 35 |
+
template<class U> constexpr optional& operator=(optional<U>&&);
|
| 36 |
+
template<class... Args> constexpr T& emplace(Args&&...);
|
| 37 |
+
template<class U, class... Args> constexpr T& emplace(initializer_list<U>, Args&&...);
|
| 38 |
+
|
| 39 |
+
// [optional.swap], swap
|
| 40 |
+
constexpr void swap(optional&) noexcept(see below);
|
| 41 |
+
|
| 42 |
+
// [optional.observe], observers
|
| 43 |
+
constexpr const T* operator->() const noexcept;
|
| 44 |
+
constexpr T* operator->() noexcept;
|
| 45 |
+
constexpr const T& operator*() const & noexcept;
|
| 46 |
+
constexpr T& operator*() & noexcept;
|
| 47 |
+
constexpr T&& operator*() && noexcept;
|
| 48 |
+
constexpr const T&& operator*() const && noexcept;
|
| 49 |
+
constexpr explicit operator bool() const noexcept;
|
| 50 |
+
constexpr bool has_value() const noexcept;
|
| 51 |
+
constexpr const T& value() const &;
|
| 52 |
+
constexpr T& value() &;
|
| 53 |
+
constexpr T&& value() &&;
|
| 54 |
+
constexpr const T&& value() const &&;
|
| 55 |
+
template<class U> constexpr T value_or(U&&) const &;
|
| 56 |
+
template<class U> constexpr T value_or(U&&) &&;
|
| 57 |
+
|
| 58 |
+
// [optional.monadic], monadic operations
|
| 59 |
+
template<class F> constexpr auto and_then(F&& f) &;
|
| 60 |
+
template<class F> constexpr auto and_then(F&& f) &&;
|
| 61 |
+
template<class F> constexpr auto and_then(F&& f) const &;
|
| 62 |
+
template<class F> constexpr auto and_then(F&& f) const &&;
|
| 63 |
+
template<class F> constexpr auto transform(F&& f) &;
|
| 64 |
+
template<class F> constexpr auto transform(F&& f) &&;
|
| 65 |
+
template<class F> constexpr auto transform(F&& f) const &;
|
| 66 |
+
template<class F> constexpr auto transform(F&& f) const &&;
|
| 67 |
+
template<class F> constexpr optional or_else(F&& f) &&;
|
| 68 |
+
template<class F> constexpr optional or_else(F&& f) const &;
|
| 69 |
+
|
| 70 |
+
// [optional.mod], modifiers
|
| 71 |
+
constexpr void reset() noexcept;
|
| 72 |
+
|
| 73 |
+
private:
|
| 74 |
+
T *val; // exposition only
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
template<class T>
|
| 78 |
+
optional(T) -> optional<T>;
|
| 79 |
+
}
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Any instance of `optional<T>` at any given time either contains a value
|
| 83 |
+
or does not contain a value. When an instance of `optional<T>` *contains
|
| 84 |
+
a value*, it means that an object of type `T`, referred to as the
|
| 85 |
+
optional object’s *contained value*, is allocated within the storage of
|
| 86 |
+
the optional object. Implementations are not permitted to use additional
|
| 87 |
+
storage, such as dynamic memory, to allocate its contained value. When
|
| 88 |
+
an object of type `optional<T>` is contextually converted to `bool`, the
|
| 89 |
+
conversion returns `true` if the object contains a value; otherwise the
|
| 90 |
+
conversion returns `false`.
|
| 91 |
+
|
| 92 |
+
When an `optional<T>` object contains a value, member `val` points to
|
| 93 |
+
the contained value.
|
| 94 |
+
|
| 95 |
+
`T` shall be a type other than cv `in_place_t` or cv `nullopt_t` that
|
| 96 |
+
meets the *Cpp17Destructible* requirements ([[cpp17.destructible]]).
|
| 97 |
+
|