168 lines
4.6 KiB
Markdown
168 lines
4.6 KiB
Markdown
[optional.observe]
|
||
|
||
# 22 General utilities library [[utilities]](./#utilities)
|
||
|
||
## 22.5 Optional objects [[optional]](optional#observe)
|
||
|
||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.observe)
|
||
|
||
#### 22.5.3.7 Observers [optional.observe]
|
||
|
||
[ð](#lib:operator-%3e,optional)
|
||
|
||
`constexpr const T* operator->() const noexcept;
|
||
constexpr T* operator->() noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4111)
|
||
|
||
*Hardened preconditions*: has_value() is true[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4115)
|
||
|
||
*Returns*: val[.](#2.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4119)
|
||
|
||
*Remarks*: These functions are constexpr functions[.](#3.sentence-1)
|
||
|
||
[ð](#lib:operator*,optional)
|
||
|
||
`constexpr const T& operator*() const & noexcept;
|
||
constexpr T& operator*() & noexcept;
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4131)
|
||
|
||
*Hardened preconditions*: has_value() is true[.](#4.sentence-1)
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4135)
|
||
|
||
*Returns*: *val[.](#5.sentence-1)
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4139)
|
||
|
||
*Remarks*: These functions are constexpr functions[.](#6.sentence-1)
|
||
|
||
[ð](#lib:operator*,optional_)
|
||
|
||
`constexpr T&& operator*() && noexcept;
|
||
constexpr const T&& operator*() const && noexcept;
|
||
`
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4151)
|
||
|
||
*Hardened preconditions*: has_value() is true[.](#7.sentence-1)
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4155)
|
||
|
||
*Effects*: Equivalent to: return std::move(*val);
|
||
|
||
[ð](#lib:operator_bool,optional)
|
||
|
||
`constexpr explicit operator bool() const noexcept;
|
||
`
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4166)
|
||
|
||
*Returns*: true if and only if *this contains a value[.](#9.sentence-1)
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4170)
|
||
|
||
*Remarks*: This function is a constexpr function[.](#10.sentence-1)
|
||
|
||
[ð](#lib:has_value,optional)
|
||
|
||
`constexpr bool has_value() const noexcept;
|
||
`
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4181)
|
||
|
||
*Returns*: true if and only if *this contains a value[.](#11.sentence-1)
|
||
|
||
[12](#12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4185)
|
||
|
||
*Remarks*: This function is a constexpr function[.](#12.sentence-1)
|
||
|
||
[ð](#lib:value,optional)
|
||
|
||
`constexpr const T& value() const &;
|
||
constexpr T& value() &;
|
||
`
|
||
|
||
[13](#13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4197)
|
||
|
||
*Effects*: Equivalent to:return has_value() ? *val : throw bad_optional_access();
|
||
|
||
[ð](#lib:value,optional_)
|
||
|
||
`constexpr T&& value() &&;
|
||
constexpr const T&& value() const &&;
|
||
`
|
||
|
||
[14](#14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4213)
|
||
|
||
*Effects*: Equivalent to:return has_value() ? std::move(*val) : throw bad_optional_access();
|
||
|
||
[ð](#lib:value_or,optional)
|
||
|
||
`template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) const &;
|
||
`
|
||
|
||
[15](#15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4227)
|
||
|
||
*Mandates*: is_copy_constructible_v<T> && is_convertible_v<U&&, T> is true[.](#15.sentence-1)
|
||
|
||
[16](#16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4231)
|
||
|
||
*Effects*: Equivalent to:return has_value() ? **this : static_cast<T>(std::forward<U>(v));
|
||
|
||
[ð](#lib:value_or,optional_)
|
||
|
||
`template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) &&;
|
||
`
|
||
|
||
[17](#17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4245)
|
||
|
||
*Mandates*: is_move_constructible_v<T> && is_convertible_v<U&&, T> is true[.](#17.sentence-1)
|
||
|
||
[18](#18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4249)
|
||
|
||
*Effects*: Equivalent to:return has_value() ? std::move(**this) : static_cast<T>(std::forward<U>(v));
|