Init
This commit is contained in:
439
cppdraft/optional/assign.md
Normal file
439
cppdraft/optional/assign.md
Normal file
@@ -0,0 +1,439 @@
|
||||
[optional.assign]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#assign)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.assign)
|
||||
|
||||
#### 22.5.3.4 Assignment [optional.assign]
|
||||
|
||||
[ð](#lib:operator=,optional)
|
||||
|
||||
`constexpr optional<T>& operator=(nullopt_t) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3669)
|
||||
|
||||
*Effects*: If *this contains a value, calls val->T::~T() to destroy the contained value; otherwise no effect[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3673)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3677)
|
||||
|
||||
*Returns*: *this[.](#3.sentence-1)
|
||||
|
||||
[ð](#lib:operator=,optional_)
|
||||
|
||||
`constexpr optional<T>& operator=(const optional& rhs);
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3688)
|
||||
|
||||
*Effects*: See Table [67](#tab:optional.assign.copy "Table 67: optional::operator=(const optional&) effects")[.](#4.sentence-1)
|
||||
|
||||
Table [67](#tab:optional.assign.copy) — optional::operator=(const optional&) effects [[tab:optional.assign.copy]](./tab:optional.assign.copy)
|
||||
|
||||
| [ð](#tab:optional.assign.copy-row-1) | | ***this contains a value** | ***this does not contain a value** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:optional.assign.copy-row-2)<br>**rhs contains a value** | | assigns *rhs to the contained value | direct-non-list-initializes the contained value with *rhs |
|
||||
| [ð](#tab:optional.assign.copy-row-3)<br>**rhs does not contain a value** | | destroys the contained value by calling val->T::~T() | no effect |
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3705)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3709)
|
||||
|
||||
*Returns*: *this[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3713)
|
||||
|
||||
*Remarks*: If any exception is thrown, the result of the expression this->has_value() remains unchanged[.](#7.sentence-1)
|
||||
|
||||
If an exception is thrown during the call to T's copy constructor, no effect[.](#7.sentence-2)
|
||||
|
||||
If an exception is thrown during the call to T's copy assignment,
|
||||
the state of its contained value is as defined by the exception safety guarantee of T's copy assignment[.](#7.sentence-3)
|
||||
|
||||
This operator is defined as deleted unlessis_copy_constructible_v<T> is true andis_copy_assignable_v<T> is true[.](#7.sentence-4)
|
||||
|
||||
If is_trivially_copy_constructible_v<T> &&is_trivially_copy_assignable_v<T> &&is_trivially_destructible_v<T> is true,
|
||||
this assignment operator is trivial[.](#7.sentence-5)
|
||||
|
||||
[ð](#lib:operator=,optional__)
|
||||
|
||||
`constexpr optional& operator=(optional&& rhs) noexcept(see below);
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3734)
|
||||
|
||||
*Constraints*: is_move_constructible_v<T> is true andis_move_assignable_v<T> is true[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3739)
|
||||
|
||||
*Effects*: See Table [68](#tab:optional.assign.move "Table 68: optional::operator=(optional&&) effects")[.](#9.sentence-1)
|
||||
|
||||
The result of the expression rhs.has_value() remains unchanged[.](#9.sentence-2)
|
||||
|
||||
Table [68](#tab:optional.assign.move) — optional::operator=(optional&&) effects [[tab:optional.assign.move]](./tab:optional.assign.move)
|
||||
|
||||
| [ð](#tab:optional.assign.move-row-1) | | ***this contains a value** | ***this does not contain a value** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:optional.assign.move-row-2)<br>**rhs contains a value** | | assigns *std::move(rhs) to the contained value | direct-non-list-initializes the contained value with *std::move(rhs) |
|
||||
| [ð](#tab:optional.assign.move-row-3)<br>**rhs does not contain a value** | | destroys the contained value by calling val->T::~T() | no effect |
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3757)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3761)
|
||||
|
||||
*Returns*: *this[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3765)
|
||||
|
||||
*Remarks*: The exception specification is equivalent to:is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3772)
|
||||
|
||||
If any exception is thrown, the result of the expression this->has_value() remains unchanged[.](#13.sentence-1)
|
||||
|
||||
If an exception is thrown during the call to T's move constructor,
|
||||
the state of *rhs.val is determined by the exception safety guarantee of T's move constructor[.](#13.sentence-2)
|
||||
|
||||
If an exception is thrown during the call to T's move assignment,
|
||||
the state of *val and *rhs.val is determined by the exception safety guarantee of T's move assignment[.](#13.sentence-3)
|
||||
|
||||
If is_trivially_move_constructible_v<T> &&is_trivially_move_assignable_v<T> &&is_trivially_destructible_v<T> is true,
|
||||
this assignment operator is trivial[.](#13.sentence-4)
|
||||
|
||||
[ð](#lib:operator=,optional___)
|
||||
|
||||
`template<class U = remove_cv_t<T>> constexpr optional& operator=(U&& v);
|
||||
`
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3790)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(14.1)](#14.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, optional> is false,
|
||||
|
||||
- [(14.2)](#14.2)
|
||||
|
||||
conjunction_v<is_scalar<T>, is_same<T, decay_t<U>>> is false,
|
||||
|
||||
- [(14.3)](#14.3)
|
||||
|
||||
is_constructible_v<T, U> is true, and
|
||||
|
||||
- [(14.4)](#14.4)
|
||||
|
||||
is_assignable_v<T&, U> is true[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3799)
|
||||
|
||||
*Effects*: If *this contains a value, assigns std::forward<U>(v) to the contained value; otherwise direct-non-list-initializes the contained value with std::forward<U>(v)[.](#15.sentence-1)
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3803)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#16.sentence-1)
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3807)
|
||||
|
||||
*Returns*: *this[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3811)
|
||||
|
||||
*Remarks*: If any exception is thrown, the result of the expression this->has_value() remains unchanged[.](#18.sentence-1)
|
||||
|
||||
If an exception is thrown during the call to T's constructor, the state of v is determined by the exception safety guarantee of T's constructor[.](#18.sentence-2)
|
||||
|
||||
If an exception is thrown during the call to T's assignment, the state of *val and v is determined by the exception safety guarantee of T's assignment[.](#18.sentence-3)
|
||||
|
||||
[ð](#lib:operator=,optional____)
|
||||
|
||||
`template<class U> constexpr optional<T>& operator=(const optional<U>& rhs);
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3822)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(19.1)](#19.1)
|
||||
|
||||
is_constructible_v<T, const U&> is true,
|
||||
|
||||
- [(19.2)](#19.2)
|
||||
|
||||
is_assignable_v<T&, const U&> is true,
|
||||
|
||||
- [(19.3)](#19.3)
|
||||
|
||||
*converts-from-any-cvref*<T, optional<U>> is false,
|
||||
|
||||
- [(19.4)](#19.4)
|
||||
|
||||
is_assignable_v<T&, optional<U>&> is false,
|
||||
|
||||
- [(19.5)](#19.5)
|
||||
|
||||
is_assignable_v<T&, optional<U>&&> is false,
|
||||
|
||||
- [(19.6)](#19.6)
|
||||
|
||||
is_assignable_v<T&, const optional<U>&> is false, and
|
||||
|
||||
- [(19.7)](#19.7)
|
||||
|
||||
is_assignable_v<T&, const optional<U>&&> is false[.](#19.sentence-1)
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3834)
|
||||
|
||||
*Effects*: See Table [69](#tab:optional.assign.copy.templ "Table 69: optional::operator=(const optional<U>&) effects")[.](#20.sentence-1)
|
||||
|
||||
Table [69](#tab:optional.assign.copy.templ) — optional::operator=(const optional<U>&) effects [[tab:optional.assign.copy.templ]](./tab:optional.assign.copy.templ)
|
||||
|
||||
| [ð](#tab:optional.assign.copy.templ-row-1) | | ***this contains a value** | ***this does not contain a value** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:optional.assign.copy.templ-row-2)<br>**rhs contains a value** | | assigns *rhs to the contained value | direct-non-list-initializes the contained value with *rhs |
|
||||
| [ð](#tab:optional.assign.copy.templ-row-3)<br>**rhs does not contain a value** | | destroys the contained value by calling val->T::~T() | no effect |
|
||||
|
||||
[21](#21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3851)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#21.sentence-1)
|
||||
|
||||
[22](#22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3855)
|
||||
|
||||
*Returns*: *this[.](#22.sentence-1)
|
||||
|
||||
[23](#23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3859)
|
||||
|
||||
*Remarks*: If any exception is thrown,
|
||||
the result of the expression this->has_value() remains unchanged[.](#23.sentence-1)
|
||||
|
||||
If an exception is thrown during the call to T's constructor,
|
||||
the state of *rhs.val is determined by
|
||||
the exception safety guarantee of T's constructor[.](#23.sentence-2)
|
||||
|
||||
If an exception is thrown during the call to T's assignment,
|
||||
the state of *val and *rhs.val is determined by
|
||||
the exception safety guarantee of T's assignment[.](#23.sentence-3)
|
||||
|
||||
[ð](#lib:operator=,optional_____)
|
||||
|
||||
`template<class U> constexpr optional<T>& operator=(optional<U>&& rhs);
|
||||
`
|
||||
|
||||
[24](#24)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3877)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(24.1)](#24.1)
|
||||
|
||||
is_constructible_v<T, U> is true,
|
||||
|
||||
- [(24.2)](#24.2)
|
||||
|
||||
is_assignable_v<T&, U> is true,
|
||||
|
||||
- [(24.3)](#24.3)
|
||||
|
||||
*converts-from-any-cvref*<T, optional<U>> is false,
|
||||
|
||||
- [(24.4)](#24.4)
|
||||
|
||||
is_assignable_v<T&, optional<U>&> is false,
|
||||
|
||||
- [(24.5)](#24.5)
|
||||
|
||||
is_assignable_v<T&, optional<U>&&> is false,
|
||||
|
||||
- [(24.6)](#24.6)
|
||||
|
||||
is_assignable_v<T&, const optional<U>&> is false, and
|
||||
|
||||
- [(24.7)](#24.7)
|
||||
|
||||
is_assignable_v<T&, const optional<U>&&> is false[.](#24.sentence-1)
|
||||
|
||||
[25](#25)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3889)
|
||||
|
||||
*Effects*: See Table [70](#tab:optional.assign.move.templ "Table 70: optional::operator=(optional<U>&&) effects")[.](#25.sentence-1)
|
||||
|
||||
The result of the expression rhs.has_value() remains unchanged[.](#25.sentence-2)
|
||||
|
||||
Table [70](#tab:optional.assign.move.templ) — optional::operator=(optional<U>&&) effects [[tab:optional.assign.move.templ]](./tab:optional.assign.move.templ)
|
||||
|
||||
| [ð](#tab:optional.assign.move.templ-row-1) | | ***this contains a value** | ***this does not contain a value** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:optional.assign.move.templ-row-2)<br>**rhs contains a value** | | assigns *std::move(rhs) to the contained value | direct-non-list-initializes the contained value with *std::move(rhs) |
|
||||
| [ð](#tab:optional.assign.move.templ-row-3)<br>**rhs does not contain a value** | | destroys the contained value by calling val->T::~T() | no effect |
|
||||
|
||||
[26](#26)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3907)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#26.sentence-1)
|
||||
|
||||
[27](#27)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3911)
|
||||
|
||||
*Returns*: *this[.](#27.sentence-1)
|
||||
|
||||
[28](#28)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3915)
|
||||
|
||||
*Remarks*: If any exception is thrown,
|
||||
the result of the expression this->has_value() remains unchanged[.](#28.sentence-1)
|
||||
|
||||
If an exception is thrown during the call to T's constructor,
|
||||
the state of *rhs.val is determined by
|
||||
the exception safety guarantee of T's constructor[.](#28.sentence-2)
|
||||
|
||||
If an exception is thrown during the call to T's assignment,
|
||||
the state of *val and *rhs.val is determined by
|
||||
the exception safety guarantee of T's assignment[.](#28.sentence-3)
|
||||
|
||||
[ð](#lib:emplace,optional)
|
||||
|
||||
`template<class... Args> constexpr T& emplace(Args&&... args);
|
||||
`
|
||||
|
||||
[29](#29)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3933)
|
||||
|
||||
*Mandates*: is_constructible_v<T, Args...> is true[.](#29.sentence-1)
|
||||
|
||||
[30](#30)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3937)
|
||||
|
||||
*Effects*: Calls *this = nullopt[.](#30.sentence-1)
|
||||
|
||||
Then direct-non-list-initializes the contained value
|
||||
with std::forward<Args>(args)...[.](#30.sentence-2)
|
||||
|
||||
[31](#31)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3942)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#31.sentence-1)
|
||||
|
||||
[32](#32)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3946)
|
||||
|
||||
*Returns*: A reference to the new contained value[.](#32.sentence-1)
|
||||
|
||||
[33](#33)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3950)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#33.sentence-1)
|
||||
|
||||
[34](#34)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3954)
|
||||
|
||||
*Remarks*: If an exception is thrown during the call to T's constructor, *this does not contain a value, and the previous *val (if any) has been destroyed[.](#34.sentence-1)
|
||||
|
||||
[ð](#lib:emplace,optional_)
|
||||
|
||||
`template<class U, class... Args> constexpr T& emplace(initializer_list<U> il, Args&&... args);
|
||||
`
|
||||
|
||||
[35](#35)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3965)
|
||||
|
||||
*Constraints*: is_constructible_v<T, initializer_list<U>&, Args...> is true[.](#35.sentence-1)
|
||||
|
||||
[36](#36)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3969)
|
||||
|
||||
*Effects*: Calls *this = nullopt[.](#36.sentence-1)
|
||||
|
||||
Then direct-non-list-initializes the contained value withil, std::forward<Args>(args)...[.](#36.sentence-2)
|
||||
|
||||
[37](#37)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3974)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#37.sentence-1)
|
||||
|
||||
[38](#38)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3978)
|
||||
|
||||
*Returns*: A reference to the new contained value[.](#38.sentence-1)
|
||||
|
||||
[39](#39)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3982)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#39.sentence-1)
|
||||
|
||||
[40](#40)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3986)
|
||||
|
||||
*Remarks*: If an exception is thrown during the call to T's constructor, *this does not contain a value, and the previous *val (if any) has been destroyed[.](#40.sentence-1)
|
||||
28
cppdraft/optional/bad/access.md
Normal file
28
cppdraft/optional/bad/access.md
Normal file
@@ -0,0 +1,28 @@
|
||||
[optional.bad.access]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#bad.access)
|
||||
|
||||
### 22.5.6 Class bad_optional_access [optional.bad.access]
|
||||
|
||||
namespace std {class bad_optional_access : public exception {public:// see [[exception]](exception "17.9.3 Class exception") for the specification of the special member functionsconstexpr const char* what() const noexcept override; };}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5018)
|
||||
|
||||
The class bad_optional_access defines the type of objects thrown as exceptions to report the situation where an attempt is made to access the value of an optional object that does not contain a value[.](#1.sentence-1)
|
||||
|
||||
[ð](#lib:what,bad_optional_access)
|
||||
|
||||
`constexpr const char* what() const noexcept override;
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5027)
|
||||
|
||||
*Returns*: An implementation-defined ntbs,
|
||||
which during constant evaluation is encoded with
|
||||
the ordinary literal encoding ([[lex.ccon]](lex.ccon "5.13.3 Character literals"))[.](#2.sentence-1)
|
||||
267
cppdraft/optional/comp/with/t.md
Normal file
267
cppdraft/optional/comp/with/t.md
Normal file
@@ -0,0 +1,267 @@
|
||||
[optional.comp.with.t]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#comp.with.t)
|
||||
|
||||
### 22.5.9 Comparison with T [optional.comp.with.t]
|
||||
|
||||
[ð](#lib:operator==,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator==(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5232)
|
||||
|
||||
*Constraints*: U is not a specialization of optional[.](#1.sentence-1)
|
||||
|
||||
The expression *x == v is well-formed and
|
||||
its result is convertible to bool[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
T need not be [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]")[.](#1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5241)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x == v : false;
|
||||
|
||||
[ð](#lib:operator==,optional_)
|
||||
|
||||
`template<class T, class U> constexpr bool operator==(const T& v, const optional<U>& x);
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5252)
|
||||
|
||||
*Constraints*: T is not a specialization of optional[.](#3.sentence-1)
|
||||
|
||||
The expression v == *x is well-formed and
|
||||
its result is convertible to bool[.](#3.sentence-2)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5258)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? v == *x : false;
|
||||
|
||||
[ð](#lib:operator!=,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator!=(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5269)
|
||||
|
||||
*Constraints*: U is not a specialization of optional[.](#5.sentence-1)
|
||||
|
||||
The expression *x != v is well-formed and
|
||||
its result is convertible to bool[.](#5.sentence-2)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5275)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x != v : true;
|
||||
|
||||
[ð](#lib:operator!=,optional_)
|
||||
|
||||
`template<class T, class U> constexpr bool operator!=(const T& v, const optional<U>& x);
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5286)
|
||||
|
||||
*Constraints*: T is not a specialization of optional[.](#7.sentence-1)
|
||||
|
||||
The expression v != *x is well-formed and
|
||||
its result is convertible to bool[.](#7.sentence-2)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5292)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? v != *x : true;
|
||||
|
||||
[ð](#lib:operator%3c,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator<(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5303)
|
||||
|
||||
*Constraints*: U is not a specialization of optional[.](#9.sentence-1)
|
||||
|
||||
The expression *x < v is well-formed and
|
||||
its result is convertible to bool[.](#9.sentence-2)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5309)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x < v : true;
|
||||
|
||||
[ð](#lib:operator%3c,optional_)
|
||||
|
||||
`template<class T, class U> constexpr bool operator<(const T& v, const optional<U>& x);
|
||||
`
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5320)
|
||||
|
||||
*Constraints*: T is not a specialization of optional[.](#11.sentence-1)
|
||||
|
||||
The expression v < *x is well-formed and
|
||||
its result is convertible to bool[.](#11.sentence-2)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5326)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? v < *x : false;
|
||||
|
||||
[ð](#lib:operator%3e,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator>(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5337)
|
||||
|
||||
*Constraints*: U is not a specialization of optional[.](#13.sentence-1)
|
||||
|
||||
The expression *x > v is well-formed and
|
||||
its result is convertible to bool[.](#13.sentence-2)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5343)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x > v : false;
|
||||
|
||||
[ð](#lib:operator%3e,optional_)
|
||||
|
||||
`template<class T, class U> constexpr bool operator>(const T& v, const optional<U>& x);
|
||||
`
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5354)
|
||||
|
||||
*Constraints*: T is not a specialization of optional[.](#15.sentence-1)
|
||||
|
||||
The expression v > *x is well-formed and
|
||||
its result is convertible to bool[.](#15.sentence-2)
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5360)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? v > *x : true;
|
||||
|
||||
[ð](#lib:operator%3c=,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator<=(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5371)
|
||||
|
||||
*Constraints*: U is not a specialization of optional[.](#17.sentence-1)
|
||||
|
||||
The expression *x <= v is well-formed and
|
||||
its result is convertible to bool[.](#17.sentence-2)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5377)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x <= v : true;
|
||||
|
||||
[ð](#lib:operator%3c=,optional_)
|
||||
|
||||
`template<class T, class U> constexpr bool operator<=(const T& v, const optional<U>& x);
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5388)
|
||||
|
||||
*Constraints*: T is not a specialization of optional[.](#19.sentence-1)
|
||||
|
||||
The expression v <= *x is well-formed and
|
||||
its result is convertible to bool[.](#19.sentence-2)
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5394)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? v <= *x : false;
|
||||
|
||||
[ð](#lib:operator%3e=,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator>=(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[21](#21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5405)
|
||||
|
||||
*Constraints*: U is not a specialization of optional[.](#21.sentence-1)
|
||||
|
||||
The expression *x >= v is well-formed and
|
||||
its result is convertible to bool[.](#21.sentence-2)
|
||||
|
||||
[22](#22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5411)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x >= v : false;
|
||||
|
||||
[ð](#lib:operator%3e=,optional_)
|
||||
|
||||
`template<class T, class U> constexpr bool operator>=(const T& v, const optional<U>& x);
|
||||
`
|
||||
|
||||
[23](#23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5422)
|
||||
|
||||
*Constraints*: T is not a specialization of optional[.](#23.sentence-1)
|
||||
|
||||
The expression v >= *x is well-formed and
|
||||
its result is convertible to bool[.](#23.sentence-2)
|
||||
|
||||
[24](#24)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5428)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? v >= *x : true;
|
||||
|
||||
[ð](#lib:operator%3c=%3e,optional)
|
||||
|
||||
`template<class T, class U>
|
||||
requires (<U>) && [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "17.12.4 Concept three_way_comparable [cmp.concept]")<T, U>
|
||||
constexpr compare_three_way_result_t<T, U>
|
||||
operator<=>(const optional<T>& x, const U& v);
|
||||
`
|
||||
|
||||
[25](#25)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5442)
|
||||
|
||||
*Effects*: Equivalent to: return x.has_value() ? *x <=> v : strong_ordering::less;
|
||||
329
cppdraft/optional/ctor.md
Normal file
329
cppdraft/optional/ctor.md
Normal file
@@ -0,0 +1,329 @@
|
||||
[optional.ctor]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ctor)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.ctor)
|
||||
|
||||
#### 22.5.3.2 Constructors [optional.ctor]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3389)
|
||||
|
||||
The exposition-only variable template *converts-from-any-cvref* is used by some constructors for optional[.](#1.sentence-1)
|
||||
|
||||
template<class T, class W>constexpr bool *converts-from-any-cvref* = // *exposition only* disjunction_v<is_constructible<T, W&>, is_convertible<W&, T>,
|
||||
is_constructible<T, W>, is_convertible<W, T>,
|
||||
is_constructible<T, const W&>, is_convertible<const W&, T>,
|
||||
is_constructible<T, const W>, is_convertible<const W, T>>;
|
||||
|
||||
[ð](#lib:optional,constructor)
|
||||
|
||||
`constexpr optional() noexcept;
|
||||
constexpr optional(nullopt_t) noexcept;
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3408)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3412)
|
||||
|
||||
*Remarks*: No contained value is initialized[.](#3.sentence-1)
|
||||
|
||||
For every object type T these constructors are constexpr constructors ([[dcl.constexpr]](dcl.constexpr "9.2.6 The constexpr and consteval specifiers"))[.](#3.sentence-2)
|
||||
|
||||
[ð](#lib:optional,constructor_)
|
||||
|
||||
`constexpr optional(const optional& rhs);
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3424)
|
||||
|
||||
*Effects*: If rhs contains a value, direct-non-list-initializes the contained value
|
||||
with *rhs[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3429)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3433)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3437)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted unlessis_copy_constructible_v<T> is true[.](#7.sentence-1)
|
||||
|
||||
If is_trivially_copy_constructible_v<T> is true,
|
||||
this constructor is trivial[.](#7.sentence-2)
|
||||
|
||||
[ð](#lib:optional,constructor__)
|
||||
|
||||
`constexpr optional(optional&& rhs) noexcept(see below);
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3451)
|
||||
|
||||
*Constraints*: is_move_constructible_v<T> is true[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3455)
|
||||
|
||||
*Effects*: If rhs contains a value, direct-non-list-initializes the contained value
|
||||
with *std::move(rhs)[.](#9.sentence-1)
|
||||
|
||||
rhs.has_value() is unchanged[.](#9.sentence-2)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3461)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3465)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3469)
|
||||
|
||||
*Remarks*: The exception specification is equivalent tois_nothrow_move_constructible_v<T>[.](#12.sentence-1)
|
||||
|
||||
If is_trivially_move_constructible_v<T> is true,
|
||||
this constructor is trivial[.](#12.sentence-2)
|
||||
|
||||
[ð](#lib:optional,constructor___)
|
||||
|
||||
`template<class... Args> constexpr explicit optional(in_place_t, Args&&... args);
|
||||
`
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3483)
|
||||
|
||||
*Constraints*: is_constructible_v<T, Args...> is true[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3487)
|
||||
|
||||
*Effects*: Direct-non-list-initializes the contained value with std::forward<Args>(args)...[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3491)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#15.sentence-1)
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3495)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#16.sentence-1)
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3499)
|
||||
|
||||
*Remarks*: If T's constructor selected for the initialization is a constexpr constructor, this constructor is a constexpr constructor[.](#17.sentence-1)
|
||||
|
||||
[ð](#lib:optional,constructor____)
|
||||
|
||||
`template<class U, class... Args>
|
||||
constexpr explicit optional(in_place_t, initializer_list<U> il, Args&&... args);
|
||||
`
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3511)
|
||||
|
||||
*Constraints*: is_constructible_v<T, initializer_list<U>&, Args...> is true[.](#18.sentence-1)
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3515)
|
||||
|
||||
*Effects*: Direct-non-list-initializes the contained value with il, std::forward<Args>(args)...[.](#19.sentence-1)
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3519)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#20.sentence-1)
|
||||
|
||||
[21](#21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3523)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#21.sentence-1)
|
||||
|
||||
[22](#22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3527)
|
||||
|
||||
*Remarks*: If T's constructor selected for the initialization is a constexpr constructor, this constructor is a constexpr constructor[.](#22.sentence-1)
|
||||
|
||||
[ð](#lib:optional,constructor_____)
|
||||
|
||||
`template<class U = remove_cv_t<T>> constexpr explicit(see below) optional(U&& v);
|
||||
`
|
||||
|
||||
[23](#23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3538)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(23.1)](#23.1)
|
||||
|
||||
is_constructible_v<T, U> is true,
|
||||
|
||||
- [(23.2)](#23.2)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, in_place_t> is false,
|
||||
|
||||
- [(23.3)](#23.3)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, optional> is false, and
|
||||
|
||||
- [(23.4)](#23.4)
|
||||
|
||||
if T is cv bool,remove_cvref_t<U> is not a specialization of optional[.](#23.sentence-1)
|
||||
|
||||
[24](#24)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3548)
|
||||
|
||||
*Effects*: Direct-non-list-initializes the contained value with std::forward<U>(v)[.](#24.sentence-1)
|
||||
|
||||
[25](#25)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3552)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#25.sentence-1)
|
||||
|
||||
[26](#26)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3556)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#26.sentence-1)
|
||||
|
||||
[27](#27)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3560)
|
||||
|
||||
*Remarks*: If T's selected constructor is a constexpr constructor,
|
||||
this constructor is a constexpr constructor[.](#27.sentence-1)
|
||||
|
||||
The expression inside explicit is equivalent to:!is_convertible_v<U, T>
|
||||
|
||||
[ð](#lib:optional,constructor______)
|
||||
|
||||
`template<class U> constexpr explicit(see below) optional(const optional<U>& rhs);
|
||||
`
|
||||
|
||||
[28](#28)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3576)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(28.1)](#28.1)
|
||||
|
||||
is_constructible_v<T, const U&> is true, and
|
||||
|
||||
- [(28.2)](#28.2)
|
||||
|
||||
if T is not cv bool,*converts-from-any-cvref*<T, optional<U>> is false[.](#28.sentence-1)
|
||||
|
||||
[29](#29)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3584)
|
||||
|
||||
*Effects*: If rhs contains a value,
|
||||
direct-non-list-initializes the contained value with *rhs[.](#29.sentence-1)
|
||||
|
||||
[30](#30)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3589)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#30.sentence-1)
|
||||
|
||||
[31](#31)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3593)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#31.sentence-1)
|
||||
|
||||
[32](#32)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3597)
|
||||
|
||||
*Remarks*: The expression inside explicit is equivalent to:!is_convertible_v<const U&, T>
|
||||
|
||||
[ð](#lib:optional,constructor_______)
|
||||
|
||||
`template<class U> constexpr explicit(see below) optional(optional<U>&& rhs);
|
||||
`
|
||||
|
||||
[33](#33)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3611)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(33.1)](#33.1)
|
||||
|
||||
is_constructible_v<T, U> is true, and
|
||||
|
||||
- [(33.2)](#33.2)
|
||||
|
||||
if T is not cv bool,*converts-from-any-cvref*<T, optional<U>> is false[.](#33.sentence-1)
|
||||
|
||||
[34](#34)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3619)
|
||||
|
||||
*Effects*: If rhs contains a value,
|
||||
direct-non-list-initializes the contained value with *std::move(rhs)[.](#34.sentence-1)
|
||||
|
||||
rhs.has_value() is unchanged[.](#34.sentence-2)
|
||||
|
||||
[35](#35)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3625)
|
||||
|
||||
*Postconditions*: rhs.has_value() == this->has_value()[.](#35.sentence-1)
|
||||
|
||||
[36](#36)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3629)
|
||||
|
||||
*Throws*: Any exception thrown by the selected constructor of T[.](#36.sentence-1)
|
||||
|
||||
[37](#37)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3633)
|
||||
|
||||
*Remarks*: The expression inside explicit is equivalent to:!is_convertible_v<U, T>
|
||||
26
cppdraft/optional/dtor.md
Normal file
26
cppdraft/optional/dtor.md
Normal file
@@ -0,0 +1,26 @@
|
||||
[optional.dtor]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#dtor)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.dtor)
|
||||
|
||||
#### 22.5.3.3 Destructor [optional.dtor]
|
||||
|
||||
[ð](#lib:optional,destructor)
|
||||
|
||||
`constexpr ~optional();
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3649)
|
||||
|
||||
*Effects*: If is_trivially_destructible_v<T> != true and *this contains a value, callsval->T::~T()
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3656)
|
||||
|
||||
*Remarks*: If is_trivially_destructible_v<T> is true, then this destructor is trivial[.](#2.sentence-1)
|
||||
25
cppdraft/optional/general.md
Normal file
25
cppdraft/optional/general.md
Normal file
@@ -0,0 +1,25 @@
|
||||
[optional.general]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#general)
|
||||
|
||||
### 22.5.1 General [optional.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3169)
|
||||
|
||||
Subclause [[optional]](optional "22.5 Optional objects") describes class template optional that represents
|
||||
optional objects[.](#1.sentence-1)
|
||||
|
||||
An [*optional object*](#def:optional_object "22.5.1 General [optional.general]") is an
|
||||
object that contains the storage for another object and manages the lifetime of
|
||||
this contained object, if any[.](#1.sentence-2)
|
||||
|
||||
The contained object may be initialized after
|
||||
the optional object has been initialized, and may be destroyed before the
|
||||
optional object has been destroyed[.](#1.sentence-3)
|
||||
|
||||
The initialization state of the contained
|
||||
object is tracked by the optional object[.](#1.sentence-4)
|
||||
25
cppdraft/optional/hash.md
Normal file
25
cppdraft/optional/hash.md
Normal file
@@ -0,0 +1,25 @@
|
||||
[optional.hash]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#hash)
|
||||
|
||||
### 22.5.11 Hash support [optional.hash]
|
||||
|
||||
[ð](#lib:hash,optional)
|
||||
|
||||
`template<class T> struct hash<optional<T>>;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5517)
|
||||
|
||||
The specialization hash<optional<T>> is enabled ([[unord.hash]](unord.hash "22.10.19 Class template hash"))
|
||||
if and only if hash<remove_const_t<T>> is enabled[.](#1.sentence-1)
|
||||
|
||||
When enabled, for an object o of type optional<T>,
|
||||
if o.has_value() == true, then hash<optional<T>>()(o) evaluates to the same value as hash<remove_const_t<T>>()(*o);
|
||||
otherwise it evaluates to an unspecified value[.](#1.sentence-2)
|
||||
|
||||
The member functions are not guaranteed to be noexcept[.](#1.sentence-3)
|
||||
66
cppdraft/optional/iterators.md
Normal file
66
cppdraft/optional/iterators.md
Normal file
@@ -0,0 +1,66 @@
|
||||
[optional.iterators]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#iterators)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.iterators)
|
||||
|
||||
#### 22.5.3.6 Iterator support [optional.iterators]
|
||||
|
||||
[ð](#lib:iterator,optional)
|
||||
|
||||
`using iterator = implementation-defined;
|
||||
using const_iterator = implementation-defined;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4059)
|
||||
|
||||
These types
|
||||
model [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]") ([[iterator.concept.contiguous]](iterator.concept.contiguous "24.3.4.14 Concept contiguous_iterator")),
|
||||
meet the [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")), and
|
||||
meet the requirements for constexpr iterators ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")),
|
||||
with value type remove_cv_t<T>[.](#1.sentence-1)
|
||||
|
||||
The reference type is T& for iterator andconst T& for const_iterator[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4068)
|
||||
|
||||
All requirements on container iterators ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements")) apply tooptional::iterator and optional::const_iterator as well[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4072)
|
||||
|
||||
Any operation that initializes or destroys the contained value of an optional object invalidates all iterators into that object[.](#3.sentence-1)
|
||||
|
||||
[ð](#lib:begin,optional)
|
||||
|
||||
`constexpr iterator begin() noexcept;
|
||||
constexpr const_iterator begin() const noexcept;
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4083)
|
||||
|
||||
*Returns*: If has_value() is true,
|
||||
an iterator referring to the contained value[.](#4.sentence-1)
|
||||
|
||||
Otherwise, a past-the-end iterator value[.](#4.sentence-2)
|
||||
|
||||
[ð](#lib:end,optional)
|
||||
|
||||
`constexpr iterator end() noexcept;
|
||||
constexpr const_iterator end() const noexcept;
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4097)
|
||||
|
||||
*Returns*: begin() + has_value()[.](#5.sentence-1)
|
||||
27
cppdraft/optional/mod.md
Normal file
27
cppdraft/optional/mod.md
Normal file
@@ -0,0 +1,27 @@
|
||||
[optional.mod]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#mod)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.mod)
|
||||
|
||||
#### 22.5.3.9 Modifiers [optional.mod]
|
||||
|
||||
[ð](#lib:reset,optional)
|
||||
|
||||
`constexpr void reset() noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4434)
|
||||
|
||||
*Effects*: If *this contains a value, calls val->T::~T() to destroy the contained value;
|
||||
otherwise no effect[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4439)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#2.sentence-1)
|
||||
171
cppdraft/optional/monadic.md
Normal file
171
cppdraft/optional/monadic.md
Normal file
@@ -0,0 +1,171 @@
|
||||
[optional.monadic]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#monadic)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.monadic)
|
||||
|
||||
#### 22.5.3.8 Monadic operations [optional.monadic]
|
||||
|
||||
[ð](#lib:and_then,optional)
|
||||
|
||||
`template<class F> constexpr auto and_then(F&& f) &;
|
||||
template<class F> constexpr auto and_then(F&& f) const &;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4266)
|
||||
|
||||
Let U be invoke_result_t<F, decltype(**val*)>[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4269)
|
||||
|
||||
*Mandates*: remove_cvref_t<U> is a specialization of optional[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4273)
|
||||
|
||||
*Effects*: Equivalent to:if (*this) {return invoke(std::forward<F>(f), **val*);} else {return remove_cvref_t<U>();}
|
||||
|
||||
[ð](#lib:and_then,optional_)
|
||||
|
||||
`template<class F> constexpr auto and_then(F&& f) &&;
|
||||
template<class F> constexpr auto and_then(F&& f) const &&;
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4292)
|
||||
|
||||
Let U be invoke_result_t<F, decltype(std::move(**val*))>[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4295)
|
||||
|
||||
*Mandates*: remove_cvref_t<U> is a specialization of optional[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4299)
|
||||
|
||||
*Effects*: Equivalent to:if (*this) {return invoke(std::forward<F>(f), std::move(**val*));} else {return remove_cvref_t<U>();}
|
||||
|
||||
[ð](#lib:transform,optional)
|
||||
|
||||
`template<class F> constexpr auto transform(F&& f) &;
|
||||
template<class F> constexpr auto transform(F&& f) const &;
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4318)
|
||||
|
||||
Let U be remove_cv_t<invoke_result_t<F, decltype(**val*)>>[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4321)
|
||||
|
||||
*Mandates*: U is a valid contained type for optional[.](#8.sentence-1)
|
||||
|
||||
The declarationU u(invoke(std::forward<F>(f), **val*)); is well-formed for some invented variable u[.](#8.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
There is no requirement that U is movable ([[dcl.init.general]](dcl.init.general "9.5.1 General"))[.](#8.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4333)
|
||||
|
||||
*Returns*: If *this contains a value, an optional<U> object
|
||||
whose contained value is direct-non-list-initialized withinvoke(std::forward<F>(f), **val*);
|
||||
otherwise, optional<U>()[.](#9.sentence-1)
|
||||
|
||||
[ð](#lib:transform,optional_)
|
||||
|
||||
`template<class F> constexpr auto transform(F&& f) &&;
|
||||
template<class F> constexpr auto transform(F&& f) const &&;
|
||||
`
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4348)
|
||||
|
||||
Let U beremove_cv_t<invoke_result_t<F, decltype(std::move(**val*))>>[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4352)
|
||||
|
||||
*Mandates*: U is a valid contained type for optional[.](#11.sentence-1)
|
||||
|
||||
The declarationU u(invoke(std::forward<F>(f), std::move(**val*))); is well-formed for some invented variable u[.](#11.sentence-2)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
There is no requirement that U is movable ([[dcl.init.general]](dcl.init.general "9.5.1 General"))[.](#11.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4364)
|
||||
|
||||
*Returns*: If *this contains a value, an optional<U> object
|
||||
whose contained value is direct-non-list-initialized withinvoke(std::forward<F>(f), std::move(**val*));
|
||||
otherwise, optional<U>()[.](#12.sentence-1)
|
||||
|
||||
[ð](#lib:or_else,optional)
|
||||
|
||||
`template<class F> constexpr optional or_else(F&& f) const &;
|
||||
`
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4378)
|
||||
|
||||
*Constraints*: F models [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]") andT models [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]")[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4383)
|
||||
|
||||
*Mandates*: is_same_v<remove_cvref_t<invoke_result_t<F>>, optional> is true[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4387)
|
||||
|
||||
*Effects*: Equivalent to:if (*this) {return *this;} else {return std::forward<F>(f)();}
|
||||
|
||||
[ð](#lib:or_else,optional_)
|
||||
|
||||
`template<class F> constexpr optional or_else(F&& f) &&;
|
||||
`
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4405)
|
||||
|
||||
*Constraints*: F models [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]") andT models [move_constructible](concept.moveconstructible#concept:move_constructible "18.4.13 Concept move_constructible [concept.moveconstructible]")[.](#16.sentence-1)
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4410)
|
||||
|
||||
*Mandates*: is_same_v<remove_cvref_t<invoke_result_t<F>>, optional> is true[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4414)
|
||||
|
||||
*Effects*: Equivalent to:if (*this) {return std::move(*this);} else {return std::forward<F>(f)();}
|
||||
29
cppdraft/optional/nullops.md
Normal file
29
cppdraft/optional/nullops.md
Normal file
@@ -0,0 +1,29 @@
|
||||
[optional.nullops]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#nullops)
|
||||
|
||||
### 22.5.8 Comparison with nullopt [optional.nullops]
|
||||
|
||||
[ð](#lib:operator==,optional)
|
||||
|
||||
`template<class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5208)
|
||||
|
||||
*Returns*: !x[.](#1.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3c=%3e,optional)
|
||||
|
||||
`template<class T> constexpr strong_ordering operator<=>(const optional<T>& x, nullopt_t) noexcept;
|
||||
`
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5219)
|
||||
|
||||
*Returns*: x.has_value() <=> false[.](#2.sentence-1)
|
||||
28
cppdraft/optional/nullopt.md
Normal file
28
cppdraft/optional/nullopt.md
Normal file
@@ -0,0 +1,28 @@
|
||||
[optional.nullopt]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#nullopt)
|
||||
|
||||
### 22.5.5 No-value state indicator [optional.nullopt]
|
||||
|
||||
[ð](#lib:nullopt_t)
|
||||
|
||||
`struct nullopt_t{see below};
|
||||
inline constexpr nullopt_t nullopt(unspecified);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4998)
|
||||
|
||||
The struct nullopt_t is an empty class type used as a unique type to indicate the state of not containing a value for optional objects[.](#1.sentence-1)
|
||||
|
||||
In particular, optional<T> has a constructor with nullopt_t as a single argument;
|
||||
this indicates that an optional object not containing a value shall be constructed[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5003)
|
||||
|
||||
Type nullopt_t shall not have a default constructor or an initializer-list constructor, and shall not be an aggregate[.](#2.sentence-1)
|
||||
167
cppdraft/optional/observe.md
Normal file
167
cppdraft/optional/observe.md
Normal file
@@ -0,0 +1,167 @@
|
||||
[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));
|
||||
1277
cppdraft/optional/optional.md
Normal file
1277
cppdraft/optional/optional.md
Normal file
File diff suppressed because it is too large
Load Diff
45
cppdraft/optional/optional/general.md
Normal file
45
cppdraft/optional/optional/general.md
Normal file
@@ -0,0 +1,45 @@
|
||||
[optional.optional.general]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#optional.general)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#general)
|
||||
|
||||
#### 22.5.3.1 General [optional.optional.general]
|
||||
|
||||
[ð](#lib:optional)
|
||||
|
||||
namespace std {template<class T>class optional {public:using value_type = T; using iterator = *implementation-defined*; // see [[optional.iterators]](optional.iterators "22.5.3.6 Iterator support")using const_iterator = *implementation-defined*; // see [[optional.iterators]](optional.iterators "22.5.3.6 Iterator support")// [[optional.ctor]](optional.ctor "22.5.3.2 Constructors"), constructorsconstexpr optional() noexcept; constexpr optional(nullopt_t) noexcept; constexpr optional(const optional&); constexpr optional(optional&&) noexcept(*see below*); template<class... Args>constexpr explicit optional(in_place_t, Args&&...); template<class U, class... Args>constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...); template<class U = remove_cv_t<T>>constexpr explicit(*see below*) optional(U&&); template<class U>constexpr explicit(*see below*) optional(const optional<U>&); template<class U>constexpr explicit(*see below*) optional(optional<U>&&); // [[optional.dtor]](optional.dtor "22.5.3.3 Destructor"), destructorconstexpr ~optional(); // [[optional.assign]](optional.assign "22.5.3.4 Assignment"), assignmentconstexpr optional& operator=(nullopt_t) noexcept; constexpr optional& operator=(const optional&); constexpr optional& operator=(optional&&) noexcept(*see below*); template<class U = remove_cv_t<T>> constexpr optional& operator=(U&&); template<class U> constexpr optional& operator=(const optional<U>&); template<class U> constexpr optional& operator=(optional<U>&&); template<class... Args> constexpr T& emplace(Args&&...); template<class U, class... Args> constexpr T& emplace(initializer_list<U>, Args&&...); // [[optional.swap]](optional.swap "22.5.3.5 Swap"), swapconstexpr void swap(optional&) noexcept(*see below*); // [[optional.iterators]](optional.iterators "22.5.3.6 Iterator support"), iterator supportconstexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept; // [[optional.observe]](optional.observe "22.5.3.7 Observers"), observersconstexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept; constexpr const T& operator*() const & noexcept; constexpr T& operator*() & noexcept; constexpr T&& operator*() && noexcept; constexpr const T&& operator*() const && noexcept; constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; constexpr const T& value() const &; // freestanding-deletedconstexpr T& value() &; // freestanding-deletedconstexpr T&& value() &&; // freestanding-deletedconstexpr const T&& value() const &&; // freestanding-deletedtemplate<class U = remove_cv_t<T>> constexpr T value_or(U&&) const &; template<class U = remove_cv_t<T>> constexpr T value_or(U&&) &&; // [[optional.monadic]](optional.monadic "22.5.3.8 Monadic operations"), monadic operationstemplate<class F> constexpr auto and_then(F&& f) &; template<class F> constexpr auto and_then(F&& f) &&; template<class F> constexpr auto and_then(F&& f) const &; template<class F> constexpr auto and_then(F&& f) const &&; template<class F> constexpr auto transform(F&& f) &; template<class F> constexpr auto transform(F&& f) &&; template<class F> constexpr auto transform(F&& f) const &; template<class F> constexpr auto transform(F&& f) const &&; template<class F> constexpr optional or_else(F&& f) &&; template<class F> constexpr optional or_else(F&& f) const &; // [[optional.mod]](optional.mod "22.5.3.9 Modifiers"), modifiersconstexpr void reset() noexcept; private: T* *val*; // *exposition only*}; template<class T> optional(T) -> optional<T>;}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3364)
|
||||
|
||||
Any instance of optional<T> at any given time either contains a value or does not contain a value[.](#1.sentence-1)
|
||||
|
||||
When an instance of optional<T> [*contains a value*](#def:contains_a_value,optional "22.5.3.1 General [optional.optional.general]"),
|
||||
it means that an object of type T, referred to as the optional object's [*contained value*](#def:contained_value,optional "22.5.3.1 General [optional.optional.general]"),
|
||||
is nested within ([[intro.object]](intro.object "6.8.2 Object model")) the optional object[.](#1.sentence-2)
|
||||
|
||||
When an object of type optional<T> is contextually converted to bool,
|
||||
the conversion returns true if the object contains a value;
|
||||
otherwise the conversion returns false[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3373)
|
||||
|
||||
When an optional<T> object contains a value,
|
||||
member val points to the contained value[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3377)
|
||||
|
||||
A type X is a[*valid contained type*](#def:valid_contained_type,optional "22.5.3.1 General [optional.optional.general]") for optional if X is an lvalue reference type or a complete non-array object type,
|
||||
and remove_cvref_t<X> is a type other than in_place_t or nullopt_t[.](#3.sentence-1)
|
||||
|
||||
If a specialization of optional is instantiated with a type T that is not a valid contained type for optional, the program is ill-formed[.](#3.sentence-2)
|
||||
|
||||
If T is an object type,T shall meet the *Cpp17Destructible* requirements (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements"))[.](#3.sentence-3)
|
||||
564
cppdraft/optional/optional/ref.md
Normal file
564
cppdraft/optional/optional/ref.md
Normal file
@@ -0,0 +1,564 @@
|
||||
[optional.optional.ref]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#optional.ref)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [optional.optional.ref]
|
||||
|
||||
#### [22.5.4.1](#general) General [[optional.optional.ref.general]](optional.optional.ref.general)
|
||||
|
||||
namespace std {template<class T>class optional<T&> {public:using value_type = T; using iterator = *implementation-defined*; // see [[optional.ref.iterators]](#optional.ref.iterators "22.5.4.5 Iterator support")public:// [[optional.ref.ctor]](#optional.ref.ctor "22.5.4.2 Constructors"), constructorsconstexpr optional() noexcept = default; constexpr optional(nullopt_t) noexcept : optional() {}constexpr optional(const optional& rhs) noexcept = default; template<class Arg>constexpr explicit optional(in_place_t, Arg&& arg); template<class U>constexpr explicit(*see below*) optional(U&& u) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(optional<U>& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(const optional<U>& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(optional<U>&& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(const optional<U>&& rhs) noexcept(*see below*); constexpr ~optional() = default; // [[optional.ref.assign]](#optional.ref.assign "22.5.4.3 Assignment"), assignmentconstexpr optional& operator=(nullopt_t) noexcept; constexpr optional& operator=(const optional& rhs) noexcept = default; template<class U> constexpr T& emplace(U&& u) noexcept(*see below*); // [[optional.ref.swap]](#optional.ref.swap "22.5.4.4 Swap"), swapconstexpr void swap(optional& rhs) noexcept; // [[optional.ref.iterators]](#optional.ref.iterators "22.5.4.5 Iterator support"), iterator supportconstexpr iterator begin() const noexcept; constexpr iterator end() const noexcept; // [[optional.ref.observe]](#optional.ref.observe "22.5.4.6 Observers"), observersconstexpr T* operator->() const noexcept; constexpr T& operator*() const noexcept; constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; constexpr T& value() const; // freestanding-deletedtemplate<class U = remove_cv_t<T>>constexpr remove_cv_t<T> value_or(U&& u) const; // [[optional.ref.monadic]](#optional.ref.monadic "22.5.4.7 Monadic operations"), monadic operationstemplate<class F> constexpr auto and_then(F&& f) const; template<class F> constexpr optional<invoke_result_t<F, T&>> transform(F&& f) const; template<class F> constexpr optional or_else(F&& f) const; // [[optional.ref.mod]](#optional.ref.mod "22.5.4.8 Modifiers"), modifiersconstexpr void reset() noexcept; private: T* *val* = nullptr; // *exposition only*// [[optional.ref.expos]](#optional.ref.expos "22.5.4.9 Exposition only helper functions"), exposition only helper functionstemplate<class U>constexpr void *convert-ref-init-val*(U&& u); // *exposition only*};}
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4516)
|
||||
|
||||
An object of optional<T&>[*contains a value*](#def:contains_a_value,optional.ref "22.5.4.1 General [optional.optional.ref.general]") if and only if *val* != nullptr is true[.](#general-1.sentence-1)
|
||||
|
||||
When an optional<T&> contains a value,
|
||||
the [*contained value*](#def:contained_value,optional.ref "22.5.4.1 General [optional.optional.ref.general]") is a reference to **val*[.](#general-1.sentence-2)
|
||||
|
||||
#### [22.5.4.2](#optional.ref.ctor) Constructors [[optional.ref.ctor]](optional.ref.ctor)
|
||||
|
||||
[ð](#optional.ref.ctor-itemdecl:1)
|
||||
|
||||
`template<class Arg>
|
||||
constexpr explicit optional(in_place_t, Arg&& arg);
|
||||
`
|
||||
|
||||
[1](#optional.ref.ctor-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4532)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(1.1)](#optional.ref.ctor-1.1)
|
||||
|
||||
is_constructible_v<T&, Arg> is true, and
|
||||
|
||||
- [(1.2)](#optional.ref.ctor-1.2)
|
||||
|
||||
reference_constructs_from_temporary_v<T&, Arg> is false[.](#optional.ref.ctor-1.sentence-1)
|
||||
|
||||
[2](#optional.ref.ctor-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4539)
|
||||
|
||||
*Effects*: Equivalent to: *convert-ref-init-val*(std::forward<Arg>(arg))[.](#optional.ref.ctor-2.sentence-1)
|
||||
|
||||
[3](#optional.ref.ctor-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4543)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#optional.ref.ctor-3.sentence-1)
|
||||
|
||||
[ð](#optional.ref.ctor-itemdecl:2)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<U, T&>)
|
||||
optional(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
|
||||
`
|
||||
|
||||
[4](#optional.ref.ctor-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4555)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(4.1)](#optional.ref.ctor-4.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, optional> is false,
|
||||
|
||||
- [(4.2)](#optional.ref.ctor-4.2)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, in_place_t> is false, and
|
||||
|
||||
- [(4.3)](#optional.ref.ctor-4.3)
|
||||
|
||||
is_constructible_v<T&, U> is true[.](#optional.ref.ctor-4.sentence-1)
|
||||
|
||||
[5](#optional.ref.ctor-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4563)
|
||||
|
||||
*Effects*: Equivalent to: *convert-ref-init-val*(std::forward<U>(u))[.](#optional.ref.ctor-5.sentence-1)
|
||||
|
||||
[6](#optional.ref.ctor-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4567)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#optional.ref.ctor-6.sentence-1)
|
||||
|
||||
[7](#optional.ref.ctor-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4571)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true[.](#optional.ref.ctor-7.sentence-1)
|
||||
|
||||
[ð](#optional.ref.ctor-itemdecl:3)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<U&, T&>)
|
||||
optional(optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, U&>);
|
||||
`
|
||||
|
||||
[8](#optional.ref.ctor-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4587)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(8.1)](#optional.ref.ctor-8.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(8.2)](#optional.ref.ctor-8.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(8.3)](#optional.ref.ctor-8.3)
|
||||
|
||||
is_constructible_v<T&, U&> is true[.](#optional.ref.ctor-8.sentence-1)
|
||||
|
||||
[9](#optional.ref.ctor-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4595)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*rhs);
|
||||
|
||||
[10](#optional.ref.ctor-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4602)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U&> is true[.](#optional.ref.ctor-10.sentence-1)
|
||||
|
||||
[ð](#optional.ref.ctor-itemdecl:4)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<const U&, T&>)
|
||||
optional(const optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, const U&>);
|
||||
`
|
||||
|
||||
[11](#optional.ref.ctor-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4618)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(11.1)](#optional.ref.ctor-11.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(11.2)](#optional.ref.ctor-11.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(11.3)](#optional.ref.ctor-11.3)
|
||||
|
||||
is_constructible_v<T&, const U&> is true[.](#optional.ref.ctor-11.sentence-1)
|
||||
|
||||
[12](#optional.ref.ctor-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4626)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*rhs);
|
||||
|
||||
[13](#optional.ref.ctor-13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4633)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U&> is true[.](#optional.ref.ctor-13.sentence-1)
|
||||
|
||||
[ð](#optional.ref.ctor-itemdecl:5)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<U, T&>)
|
||||
optional(optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, U>);
|
||||
`
|
||||
|
||||
[14](#optional.ref.ctor-14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4649)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(14.1)](#optional.ref.ctor-14.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(14.2)](#optional.ref.ctor-14.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(14.3)](#optional.ref.ctor-14.3)
|
||||
|
||||
is_constructible_v<T&, U> is true[.](#optional.ref.ctor-14.sentence-1)
|
||||
|
||||
[15](#optional.ref.ctor-15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4657)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*std::move(rhs));
|
||||
|
||||
[16](#optional.ref.ctor-16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4664)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true[.](#optional.ref.ctor-16.sentence-1)
|
||||
|
||||
[ð](#optional.ref.ctor-itemdecl:6)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<const U, T&>)
|
||||
optional(const optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, const U>);
|
||||
`
|
||||
|
||||
[17](#optional.ref.ctor-17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4680)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(17.1)](#optional.ref.ctor-17.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(17.2)](#optional.ref.ctor-17.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(17.3)](#optional.ref.ctor-17.3)
|
||||
|
||||
is_constructible_v<T&, const U> is true[.](#optional.ref.ctor-17.sentence-1)
|
||||
|
||||
[18](#optional.ref.ctor-18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4688)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*std::move(rhs));
|
||||
|
||||
[19](#optional.ref.ctor-19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4695)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U> is true[.](#optional.ref.ctor-19.sentence-1)
|
||||
|
||||
#### [22.5.4.3](#optional.ref.assign) Assignment [[optional.ref.assign]](optional.ref.assign)
|
||||
|
||||
[ð](#optional.ref.assign-itemdecl:1)
|
||||
|
||||
`constexpr optional& operator=(nullopt_t) noexcept;
|
||||
`
|
||||
|
||||
[1](#optional.ref.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4711)
|
||||
|
||||
*Effects*: Assigns nullptr to *val*[.](#optional.ref.assign-1.sentence-1)
|
||||
|
||||
[2](#optional.ref.assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4715)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#optional.ref.assign-2.sentence-1)
|
||||
|
||||
[3](#optional.ref.assign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4719)
|
||||
|
||||
*Returns*: *this[.](#optional.ref.assign-3.sentence-1)
|
||||
|
||||
[ð](#optional.ref.assign-itemdecl:2)
|
||||
|
||||
`template<class U>
|
||||
constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
|
||||
`
|
||||
|
||||
[4](#optional.ref.assign-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4730)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(4.1)](#optional.ref.assign-4.1)
|
||||
|
||||
is_constructible_v<T&, U> is true, and
|
||||
|
||||
- [(4.2)](#optional.ref.assign-4.2)
|
||||
|
||||
reference_constructs_from_temporary_v<T&, U> is false[.](#optional.ref.assign-4.sentence-1)
|
||||
|
||||
[5](#optional.ref.assign-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4737)
|
||||
|
||||
*Effects*: Equivalent to: *convert-ref-init-val*(std::forward<U>(u))[.](#optional.ref.assign-5.sentence-1)
|
||||
|
||||
#### [22.5.4.4](#optional.ref.swap) Swap [[optional.ref.swap]](optional.ref.swap)
|
||||
|
||||
[ð](#optional.ref.swap-itemdecl:1)
|
||||
|
||||
`constexpr void swap(optional& rhs) noexcept;
|
||||
`
|
||||
|
||||
[1](#optional.ref.swap-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4749)
|
||||
|
||||
*Effects*: Equivalent to: swap(*val*, rhs.*val*)[.](#optional.ref.swap-1.sentence-1)
|
||||
|
||||
#### [22.5.4.5](#optional.ref.iterators) Iterator support [[optional.ref.iterators]](optional.ref.iterators)
|
||||
|
||||
[ð](#optional.ref.iterators-itemdecl:1)
|
||||
|
||||
`using iterator = implementation-defined;
|
||||
`
|
||||
|
||||
[1](#optional.ref.iterators-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4761)
|
||||
|
||||
This type
|
||||
models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]") ([[iterator.concept.contiguous]](iterator.concept.contiguous "24.3.4.14 Concept contiguous_iterator")),
|
||||
meets the *Cpp17RandomAccessIterator* requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")),
|
||||
and meets the requirements for constexpr iterators ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")),
|
||||
with value type remove_cv_t<T>[.](#optional.ref.iterators-1.sentence-1)
|
||||
|
||||
The reference type is T& for iterator[.](#optional.ref.iterators-1.sentence-2)
|
||||
|
||||
[2](#optional.ref.iterators-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4769)
|
||||
|
||||
All requirements on container iterators ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements")) apply tooptional::iterator[.](#optional.ref.iterators-2.sentence-1)
|
||||
|
||||
[ð](#optional.ref.iterators-itemdecl:2)
|
||||
|
||||
`constexpr iterator begin() const noexcept;
|
||||
`
|
||||
|
||||
[3](#optional.ref.iterators-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4779)
|
||||
|
||||
*Returns*: If has_value() is true,
|
||||
an iterator referring to **val*[.](#optional.ref.iterators-3.sentence-1)
|
||||
|
||||
Otherwise, a past-the-end iterator value[.](#optional.ref.iterators-3.sentence-2)
|
||||
|
||||
[ð](#optional.ref.iterators-itemdecl:3)
|
||||
|
||||
`constexpr iterator end() const noexcept;
|
||||
`
|
||||
|
||||
[4](#optional.ref.iterators-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4791)
|
||||
|
||||
*Returns*: begin() + has_value()[.](#optional.ref.iterators-4.sentence-1)
|
||||
|
||||
#### [22.5.4.6](#optional.ref.observe) Observers [[optional.ref.observe]](optional.ref.observe)
|
||||
|
||||
[ð](#optional.ref.observe-itemdecl:1)
|
||||
|
||||
`constexpr T* operator->() const noexcept;
|
||||
`
|
||||
|
||||
[1](#optional.ref.observe-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4803)
|
||||
|
||||
*Hardened preconditions*: has_value() is true[.](#optional.ref.observe-1.sentence-1)
|
||||
|
||||
[2](#optional.ref.observe-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4807)
|
||||
|
||||
*Returns*: *val*[.](#optional.ref.observe-2.sentence-1)
|
||||
|
||||
[ð](#optional.ref.observe-itemdecl:2)
|
||||
|
||||
`constexpr T& operator*() const noexcept;
|
||||
`
|
||||
|
||||
[3](#optional.ref.observe-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4818)
|
||||
|
||||
*Hardened preconditions*: has_value() is true[.](#optional.ref.observe-3.sentence-1)
|
||||
|
||||
[4](#optional.ref.observe-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4822)
|
||||
|
||||
*Returns*: **val*[.](#optional.ref.observe-4.sentence-1)
|
||||
|
||||
[ð](#optional.ref.observe-itemdecl:3)
|
||||
|
||||
`constexpr explicit operator bool() const noexcept;
|
||||
`
|
||||
|
||||
[5](#optional.ref.observe-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4832)
|
||||
|
||||
*Returns*: *val* != nullptr[.](#optional.ref.observe-5.sentence-1)
|
||||
|
||||
[ð](#optional.ref.observe-itemdecl:4)
|
||||
|
||||
`constexpr bool has_value() const noexcept;
|
||||
`
|
||||
|
||||
[6](#optional.ref.observe-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4842)
|
||||
|
||||
*Returns*: *val* != nullptr[.](#optional.ref.observe-6.sentence-1)
|
||||
|
||||
[ð](#optional.ref.observe-itemdecl:5)
|
||||
|
||||
`constexpr T& value() const;
|
||||
`
|
||||
|
||||
[7](#optional.ref.observe-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4852)
|
||||
|
||||
*Effects*: Equivalent to:return has_value() ? **val* : throw bad_optional_access();
|
||||
|
||||
[ð](#optional.ref.observe-itemdecl:6)
|
||||
|
||||
`template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const;
|
||||
`
|
||||
|
||||
[8](#optional.ref.observe-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4865)
|
||||
|
||||
Let X be remove_cv_t<T>[.](#optional.ref.observe-8.sentence-1)
|
||||
|
||||
[9](#optional.ref.observe-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4868)
|
||||
|
||||
*Mandates*: is_constructible_v<X, T&> && is_convertible_v<U, X> is true[.](#optional.ref.observe-9.sentence-1)
|
||||
|
||||
[10](#optional.ref.observe-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4872)
|
||||
|
||||
*Effects*: Equivalent to:return has_value() ? **val* : static_cast<X>(std::forward<U>(u));
|
||||
|
||||
#### [22.5.4.7](#optional.ref.monadic) Monadic operations [[optional.ref.monadic]](optional.ref.monadic)
|
||||
|
||||
[ð](#optional.ref.monadic-itemdecl:1)
|
||||
|
||||
`template<class F> constexpr auto and_then(F&& f) const;
|
||||
`
|
||||
|
||||
[1](#optional.ref.monadic-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4887)
|
||||
|
||||
Let U be invoke_result_t<F, T&>[.](#optional.ref.monadic-1.sentence-1)
|
||||
|
||||
[2](#optional.ref.monadic-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4890)
|
||||
|
||||
*Mandates*: remove_cvref_t<U> is a specialization of optional[.](#optional.ref.monadic-2.sentence-1)
|
||||
|
||||
[3](#optional.ref.monadic-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4894)
|
||||
|
||||
*Effects*: Equivalent to:if (has_value()) {return invoke(std::forward<F>(f), **val*);} else {return remove_cvref_t<U>();}
|
||||
|
||||
[ð](#optional.ref.monadic-itemdecl:2)
|
||||
|
||||
`template<class F>
|
||||
constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
|
||||
`
|
||||
|
||||
[4](#optional.ref.monadic-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4912)
|
||||
|
||||
Let U be remove_cv_t<invoke_result_t<F, T&>>[.](#optional.ref.monadic-4.sentence-1)
|
||||
|
||||
[5](#optional.ref.monadic-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4915)
|
||||
|
||||
*Mandates*: The declarationU u(invoke(std::forward<F>(f), **val*)); is well-formed for some invented variable u[.](#optional.ref.monadic-5.sentence-1)
|
||||
|
||||
[*Note [1](#optional.ref.monadic-note-1)*:
|
||||
|
||||
There is no requirement that U is movable ([[dcl.init.general]](dcl.init.general "9.5.1 General"))[.](#optional.ref.monadic-5.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[6](#optional.ref.monadic-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4926)
|
||||
|
||||
*Returns*: If *this contains a value, an optional<U> object
|
||||
whose contained value is direct-non-list-initialized withinvoke(std::forward<F>(f), **val*);
|
||||
otherwise, optional<U>()[.](#optional.ref.monadic-6.sentence-1)
|
||||
|
||||
[ð](#optional.ref.monadic-itemdecl:3)
|
||||
|
||||
`template<class F> constexpr optional or_else(F&& f) const;
|
||||
`
|
||||
|
||||
[7](#optional.ref.monadic-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4939)
|
||||
|
||||
*Constraints*: F models [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")[.](#optional.ref.monadic-7.sentence-1)
|
||||
|
||||
[8](#optional.ref.monadic-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4943)
|
||||
|
||||
*Mandates*: is_same_v<remove_cvref_t<invoke_result_t<F>>, optional> is true[.](#optional.ref.monadic-8.sentence-1)
|
||||
|
||||
[9](#optional.ref.monadic-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4947)
|
||||
|
||||
*Effects*: Equivalent to:if (has_value()) {return **val*;} else {return std::forward<F>(f)();}
|
||||
|
||||
#### [22.5.4.8](#optional.ref.mod) Modifiers [[optional.ref.mod]](optional.ref.mod)
|
||||
|
||||
[ð](#optional.ref.mod-itemdecl:1)
|
||||
|
||||
`constexpr void reset() noexcept;
|
||||
`
|
||||
|
||||
[1](#optional.ref.mod-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4966)
|
||||
|
||||
*Effects*: Assigns nullptr to *val*[.](#optional.ref.mod-1.sentence-1)
|
||||
|
||||
[2](#optional.ref.mod-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4970)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#optional.ref.mod-2.sentence-1)
|
||||
|
||||
#### [22.5.4.9](#optional.ref.expos) Exposition only helper functions [[optional.ref.expos]](optional.ref.expos)
|
||||
|
||||
[ð](#optional.ref.expos-itemdecl:1)
|
||||
|
||||
`template<class U>
|
||||
constexpr void convert-ref-init-val(U&& u); // exposition only
|
||||
`
|
||||
|
||||
[1](#optional.ref.expos-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4983)
|
||||
|
||||
*Effects*: Creates a variable r as if by T& r(std::forward<U>(u)); and then initializes *val* with addressof(r)[.](#optional.ref.expos-1.sentence-1)
|
||||
20
cppdraft/optional/optional/ref/general.md
Normal file
20
cppdraft/optional/optional/ref/general.md
Normal file
@@ -0,0 +1,20 @@
|
||||
[optional.optional.ref.general]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#optional.ref.general)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#general)
|
||||
|
||||
#### 22.5.4.1 General [optional.optional.ref.general]
|
||||
|
||||
namespace std {template<class T>class optional<T&> {public:using value_type = T; using iterator = *implementation-defined*; // see [[optional.ref.iterators]](optional.ref.iterators "22.5.4.5 Iterator support")public:// [[optional.ref.ctor]](optional.ref.ctor "22.5.4.2 Constructors"), constructorsconstexpr optional() noexcept = default; constexpr optional(nullopt_t) noexcept : optional() {}constexpr optional(const optional& rhs) noexcept = default; template<class Arg>constexpr explicit optional(in_place_t, Arg&& arg); template<class U>constexpr explicit(*see below*) optional(U&& u) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(optional<U>& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(const optional<U>& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(optional<U>&& rhs) noexcept(*see below*); template<class U>constexpr explicit(*see below*) optional(const optional<U>&& rhs) noexcept(*see below*); constexpr ~optional() = default; // [[optional.ref.assign]](optional.ref.assign "22.5.4.3 Assignment"), assignmentconstexpr optional& operator=(nullopt_t) noexcept; constexpr optional& operator=(const optional& rhs) noexcept = default; template<class U> constexpr T& emplace(U&& u) noexcept(*see below*); // [[optional.ref.swap]](optional.ref.swap "22.5.4.4 Swap"), swapconstexpr void swap(optional& rhs) noexcept; // [[optional.ref.iterators]](optional.ref.iterators "22.5.4.5 Iterator support"), iterator supportconstexpr iterator begin() const noexcept; constexpr iterator end() const noexcept; // [[optional.ref.observe]](optional.ref.observe "22.5.4.6 Observers"), observersconstexpr T* operator->() const noexcept; constexpr T& operator*() const noexcept; constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept; constexpr T& value() const; // freestanding-deletedtemplate<class U = remove_cv_t<T>>constexpr remove_cv_t<T> value_or(U&& u) const; // [[optional.ref.monadic]](optional.ref.monadic "22.5.4.7 Monadic operations"), monadic operationstemplate<class F> constexpr auto and_then(F&& f) const; template<class F> constexpr optional<invoke_result_t<F, T&>> transform(F&& f) const; template<class F> constexpr optional or_else(F&& f) const; // [[optional.ref.mod]](optional.ref.mod "22.5.4.8 Modifiers"), modifiersconstexpr void reset() noexcept; private: T* *val* = nullptr; // *exposition only*// [[optional.ref.expos]](optional.ref.expos "22.5.4.9 Exposition only helper functions"), exposition only helper functionstemplate<class U>constexpr void *convert-ref-init-val*(U&& u); // *exposition only*};}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4516)
|
||||
|
||||
An object of optional<T&>[*contains a value*](#def:contains_a_value,optional.ref "22.5.4.1 General [optional.optional.ref.general]") if and only if *val* != nullptr is true[.](#1.sentence-1)
|
||||
|
||||
When an optional<T&> contains a value,
|
||||
the [*contained value*](#def:contained_value,optional.ref "22.5.4.1 General [optional.optional.ref.general]") is a reference to **val*[.](#1.sentence-2)
|
||||
58
cppdraft/optional/ref/assign.md
Normal file
58
cppdraft/optional/ref/assign.md
Normal file
@@ -0,0 +1,58 @@
|
||||
[optional.ref.assign]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.assign)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.assign)
|
||||
|
||||
#### 22.5.4.3 Assignment [optional.ref.assign]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`constexpr optional& operator=(nullopt_t) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4711)
|
||||
|
||||
*Effects*: Assigns nullptr to *val*[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4715)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4719)
|
||||
|
||||
*Returns*: *this[.](#3.sentence-1)
|
||||
|
||||
[ð](#itemdecl:2)
|
||||
|
||||
`template<class U>
|
||||
constexpr T& emplace(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4730)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
is_constructible_v<T&, U> is true, and
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
reference_constructs_from_temporary_v<T&, U> is false[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4737)
|
||||
|
||||
*Effects*: Equivalent to: *convert-ref-init-val*(std::forward<U>(u))[.](#5.sentence-1)
|
||||
232
cppdraft/optional/ref/ctor.md
Normal file
232
cppdraft/optional/ref/ctor.md
Normal file
@@ -0,0 +1,232 @@
|
||||
[optional.ref.ctor]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.ctor)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.ctor)
|
||||
|
||||
#### 22.5.4.2 Constructors [optional.ref.ctor]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`template<class Arg>
|
||||
constexpr explicit optional(in_place_t, Arg&& arg);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4532)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
is_constructible_v<T&, Arg> is true, and
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
reference_constructs_from_temporary_v<T&, Arg> is false[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4539)
|
||||
|
||||
*Effects*: Equivalent to: *convert-ref-init-val*(std::forward<Arg>(arg))[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4543)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#3.sentence-1)
|
||||
|
||||
[ð](#itemdecl:2)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<U, T&>)
|
||||
optional(U&& u) noexcept(is_nothrow_constructible_v<T&, U>);
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4555)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, optional> is false,
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, in_place_t> is false, and
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
is_constructible_v<T&, U> is true[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4563)
|
||||
|
||||
*Effects*: Equivalent to: *convert-ref-init-val*(std::forward<U>(u))[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4567)
|
||||
|
||||
*Postconditions*: *this contains a value[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4571)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true[.](#7.sentence-1)
|
||||
|
||||
[ð](#itemdecl:3)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<U&, T&>)
|
||||
optional(optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, U&>);
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4587)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(8.1)](#8.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(8.2)](#8.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(8.3)](#8.3)
|
||||
|
||||
is_constructible_v<T&, U&> is true[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4595)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*rhs);
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4602)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U&> is true[.](#10.sentence-1)
|
||||
|
||||
[ð](#itemdecl:4)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<const U&, T&>)
|
||||
optional(const optional<U>& rhs) noexcept(is_nothrow_constructible_v<T&, const U&>);
|
||||
`
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4618)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(11.1)](#11.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(11.2)](#11.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(11.3)](#11.3)
|
||||
|
||||
is_constructible_v<T&, const U&> is true[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4626)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*rhs);
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4633)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U&> is true[.](#13.sentence-1)
|
||||
|
||||
[ð](#itemdecl:5)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<U, T&>)
|
||||
optional(optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, U>);
|
||||
`
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4649)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(14.1)](#14.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(14.2)](#14.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(14.3)](#14.3)
|
||||
|
||||
is_constructible_v<T&, U> is true[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4657)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*std::move(rhs));
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4664)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, U> is true[.](#16.sentence-1)
|
||||
|
||||
[ð](#itemdecl:6)
|
||||
|
||||
`template<class U>
|
||||
constexpr explicit(!is_convertible_v<const U, T&>)
|
||||
optional(const optional<U>&& rhs) noexcept(is_nothrow_constructible_v<T&, const U>);
|
||||
`
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4680)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(17.1)](#17.1)
|
||||
|
||||
is_same_v<remove_cv_t<T>, optional<U>> is false,
|
||||
|
||||
- [(17.2)](#17.2)
|
||||
|
||||
is_same_v<T&, U> is false, and
|
||||
|
||||
- [(17.3)](#17.3)
|
||||
|
||||
is_constructible_v<T&, const U> is true[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4688)
|
||||
|
||||
*Effects*: Equivalent to:if (rhs.has_value()) *convert-ref-init-val*(*std::move(rhs));
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4695)
|
||||
|
||||
*Remarks*: This constructor is defined as deleted ifreference_constructs_from_temporary_v<T&, const U> is true[.](#19.sentence-1)
|
||||
21
cppdraft/optional/ref/expos.md
Normal file
21
cppdraft/optional/ref/expos.md
Normal file
@@ -0,0 +1,21 @@
|
||||
[optional.ref.expos]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.expos)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.expos)
|
||||
|
||||
#### 22.5.4.9 Exposition only helper functions [optional.ref.expos]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`template<class U>
|
||||
constexpr void convert-ref-init-val(U&& u); // exposition only
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4983)
|
||||
|
||||
*Effects*: Creates a variable r as if by T& r(std::forward<U>(u)); and then initializes *val* with addressof(r)[.](#1.sentence-1)
|
||||
57
cppdraft/optional/ref/iterators.md
Normal file
57
cppdraft/optional/ref/iterators.md
Normal file
@@ -0,0 +1,57 @@
|
||||
[optional.ref.iterators]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.iterators)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.iterators)
|
||||
|
||||
#### 22.5.4.5 Iterator support [optional.ref.iterators]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`using iterator = implementation-defined;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4761)
|
||||
|
||||
This type
|
||||
models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]") ([[iterator.concept.contiguous]](iterator.concept.contiguous "24.3.4.14 Concept contiguous_iterator")),
|
||||
meets the *Cpp17RandomAccessIterator* requirements ([[random.access.iterators]](random.access.iterators "24.3.5.7 Random access iterators")),
|
||||
and meets the requirements for constexpr iterators ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")),
|
||||
with value type remove_cv_t<T>[.](#1.sentence-1)
|
||||
|
||||
The reference type is T& for iterator[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4769)
|
||||
|
||||
All requirements on container iterators ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements")) apply tooptional::iterator[.](#2.sentence-1)
|
||||
|
||||
[ð](#itemdecl:2)
|
||||
|
||||
`constexpr iterator begin() const noexcept;
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4779)
|
||||
|
||||
*Returns*: If has_value() is true,
|
||||
an iterator referring to **val*[.](#3.sentence-1)
|
||||
|
||||
Otherwise, a past-the-end iterator value[.](#3.sentence-2)
|
||||
|
||||
[ð](#itemdecl:3)
|
||||
|
||||
`constexpr iterator end() const noexcept;
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4791)
|
||||
|
||||
*Returns*: begin() + has_value()[.](#4.sentence-1)
|
||||
26
cppdraft/optional/ref/mod.md
Normal file
26
cppdraft/optional/ref/mod.md
Normal file
@@ -0,0 +1,26 @@
|
||||
[optional.ref.mod]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.mod)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.mod)
|
||||
|
||||
#### 22.5.4.8 Modifiers [optional.ref.mod]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`constexpr void reset() noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4966)
|
||||
|
||||
*Effects*: Assigns nullptr to *val*[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4970)
|
||||
|
||||
*Postconditions*: *this does not contain a value[.](#2.sentence-1)
|
||||
87
cppdraft/optional/ref/monadic.md
Normal file
87
cppdraft/optional/ref/monadic.md
Normal file
@@ -0,0 +1,87 @@
|
||||
[optional.ref.monadic]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.monadic)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.monadic)
|
||||
|
||||
#### 22.5.4.7 Monadic operations [optional.ref.monadic]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`template<class F> constexpr auto and_then(F&& f) const;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4887)
|
||||
|
||||
Let U be invoke_result_t<F, T&>[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4890)
|
||||
|
||||
*Mandates*: remove_cvref_t<U> is a specialization of optional[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4894)
|
||||
|
||||
*Effects*: Equivalent to:if (has_value()) {return invoke(std::forward<F>(f), **val*);} else {return remove_cvref_t<U>();}
|
||||
|
||||
[ð](#itemdecl:2)
|
||||
|
||||
`template<class F>
|
||||
constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4912)
|
||||
|
||||
Let U be remove_cv_t<invoke_result_t<F, T&>>[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4915)
|
||||
|
||||
*Mandates*: The declarationU u(invoke(std::forward<F>(f), **val*)); is well-formed for some invented variable u[.](#5.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
There is no requirement that U is movable ([[dcl.init.general]](dcl.init.general "9.5.1 General"))[.](#5.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4926)
|
||||
|
||||
*Returns*: If *this contains a value, an optional<U> object
|
||||
whose contained value is direct-non-list-initialized withinvoke(std::forward<F>(f), **val*);
|
||||
otherwise, optional<U>()[.](#6.sentence-1)
|
||||
|
||||
[ð](#itemdecl:3)
|
||||
|
||||
`template<class F> constexpr optional or_else(F&& f) const;
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4939)
|
||||
|
||||
*Constraints*: F models [invocable](concept.invocable#concept:invocable "18.7.2 Concept invocable [concept.invocable]")[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4943)
|
||||
|
||||
*Mandates*: is_same_v<remove_cvref_t<invoke_result_t<F>>, optional> is true[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4947)
|
||||
|
||||
*Effects*: Equivalent to:if (has_value()) {return **val*;} else {return std::forward<F>(f)();}
|
||||
99
cppdraft/optional/ref/observe.md
Normal file
99
cppdraft/optional/ref/observe.md
Normal file
@@ -0,0 +1,99 @@
|
||||
[optional.ref.observe]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.observe)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.observe)
|
||||
|
||||
#### 22.5.4.6 Observers [optional.ref.observe]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`constexpr T* operator->() const noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4803)
|
||||
|
||||
*Hardened preconditions*: has_value() is true[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4807)
|
||||
|
||||
*Returns*: *val*[.](#2.sentence-1)
|
||||
|
||||
[ð](#itemdecl:2)
|
||||
|
||||
`constexpr T& operator*() const noexcept;
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4818)
|
||||
|
||||
*Hardened preconditions*: has_value() is true[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4822)
|
||||
|
||||
*Returns*: **val*[.](#4.sentence-1)
|
||||
|
||||
[ð](#itemdecl:3)
|
||||
|
||||
`constexpr explicit operator bool() const noexcept;
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4832)
|
||||
|
||||
*Returns*: *val* != nullptr[.](#5.sentence-1)
|
||||
|
||||
[ð](#itemdecl:4)
|
||||
|
||||
`constexpr bool has_value() const noexcept;
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4842)
|
||||
|
||||
*Returns*: *val* != nullptr[.](#6.sentence-1)
|
||||
|
||||
[ð](#itemdecl:5)
|
||||
|
||||
`constexpr T& value() const;
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4852)
|
||||
|
||||
*Effects*: Equivalent to:return has_value() ? **val* : throw bad_optional_access();
|
||||
|
||||
[ð](#itemdecl:6)
|
||||
|
||||
`template<class U = remove_cv_t<T>> constexpr remove_cv_t<T> value_or(U&& u) const;
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4865)
|
||||
|
||||
Let X be remove_cv_t<T>[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4868)
|
||||
|
||||
*Mandates*: is_constructible_v<X, T&> && is_convertible_v<U, X> is true[.](#9.sentence-1)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4872)
|
||||
|
||||
*Effects*: Equivalent to:return has_value() ? **val* : static_cast<X>(std::forward<U>(u));
|
||||
20
cppdraft/optional/ref/swap.md
Normal file
20
cppdraft/optional/ref/swap.md
Normal file
@@ -0,0 +1,20 @@
|
||||
[optional.ref.swap]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#ref.swap)
|
||||
|
||||
### 22.5.4 Partial specialization of optional for reference types [[optional.optional.ref]](optional.optional.ref#optional.ref.swap)
|
||||
|
||||
#### 22.5.4.4 Swap [optional.ref.swap]
|
||||
|
||||
[ð](#itemdecl:1)
|
||||
|
||||
`constexpr void swap(optional& rhs) noexcept;
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4749)
|
||||
|
||||
*Effects*: Equivalent to: swap(*val*, rhs.*val*)[.](#1.sentence-1)
|
||||
200
cppdraft/optional/relops.md
Normal file
200
cppdraft/optional/relops.md
Normal file
@@ -0,0 +1,200 @@
|
||||
[optional.relops]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#relops)
|
||||
|
||||
### 22.5.7 Relational operators [optional.relops]
|
||||
|
||||
[ð](#lib:operator==,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator==(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5042)
|
||||
|
||||
*Constraints*: The expression *x == *y is well-formed and
|
||||
its result is convertible to bool[.](#1.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
T need not be [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]")[.](#1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5050)
|
||||
|
||||
*Returns*: If x.has_value() != y.has_value(), false; otherwise if x.has_value() == false, true; otherwise *x == *y[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5054)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x == *y is a core constant expression
|
||||
are constexpr functions[.](#3.sentence-1)
|
||||
|
||||
[ð](#lib:operator!=,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator!=(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5067)
|
||||
|
||||
*Constraints*: The expression *x != *y is well-formed and
|
||||
its result is convertible to bool[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5072)
|
||||
|
||||
*Returns*: If x.has_value() != y.has_value(), true;
|
||||
otherwise, if x.has_value() == false, false;
|
||||
otherwise *x != *y[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5078)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x != *y is a core constant expression
|
||||
are constexpr functions[.](#6.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3c,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator<(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5091)
|
||||
|
||||
*Constraints*: *x < *y is well-formed
|
||||
and its result is convertible to bool[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5096)
|
||||
|
||||
*Returns*: If !y, false;
|
||||
otherwise, if !x, true;
|
||||
otherwise *x < *y[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5102)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x < *y is a core constant expression
|
||||
are constexpr functions[.](#9.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3e,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator>(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5115)
|
||||
|
||||
*Constraints*: The expression *x > *y is well-formed and
|
||||
its result is convertible to bool[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5120)
|
||||
|
||||
*Returns*: If !x, false;
|
||||
otherwise, if !y, true;
|
||||
otherwise *x > *y[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5126)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x > *y is a core constant expression
|
||||
are constexpr functions[.](#12.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3c=,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator<=(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5139)
|
||||
|
||||
*Constraints*: The expression *x <= *y is well-formed and
|
||||
its result is convertible to bool[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5144)
|
||||
|
||||
*Returns*: If !x, true;
|
||||
otherwise, if !y, false;
|
||||
otherwise *x <= *y[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5150)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x <= *y is a core constant expression
|
||||
are constexpr functions[.](#15.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3e=,optional)
|
||||
|
||||
`template<class T, class U> constexpr bool operator>=(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5163)
|
||||
|
||||
*Constraints*: The expression *x >= *y is well-formed and
|
||||
its result is convertible to bool[.](#16.sentence-1)
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5168)
|
||||
|
||||
*Returns*: If !y, true;
|
||||
otherwise, if !x, false;
|
||||
otherwise *x >= *y[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5174)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x >= *y is a core constant expression
|
||||
are constexpr functions[.](#18.sentence-1)
|
||||
|
||||
[ð](#lib:operator%3c=%3e,optional)
|
||||
|
||||
`template<class T, [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "17.12.4 Concept three_way_comparable [cmp.concept]")<T> U>
|
||||
constexpr compare_three_way_result_t<T, U>
|
||||
operator<=>(const optional<T>& x, const optional<U>& y);
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5189)
|
||||
|
||||
*Returns*: If x && y, *x <=> *y; otherwise x.has_value() <=> y.has_value()[.](#19.sentence-1)
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5193)
|
||||
|
||||
*Remarks*: Specializations of this function template
|
||||
for which *x <=> *y is a core constant expression
|
||||
are constexpr functions[.](#20.sentence-1)
|
||||
68
cppdraft/optional/specalg.md
Normal file
68
cppdraft/optional/specalg.md
Normal file
@@ -0,0 +1,68 @@
|
||||
[optional.specalg]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#specalg)
|
||||
|
||||
### 22.5.10 Specialized algorithms [optional.specalg]
|
||||
|
||||
[ð](#lib:swap,optional)
|
||||
|
||||
`template<class T>
|
||||
constexpr void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5456)
|
||||
|
||||
*Constraints*: is_reference_v<T> || (is_move_constructible_v<T> && is_swappable_v<T>) is true[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5463)
|
||||
|
||||
*Effects*: Calls x.swap(y)[.](#2.sentence-1)
|
||||
|
||||
[ð](#lib:make_optional)
|
||||
|
||||
`template<class T> constexpr optional<decay_t<T>> make_optional(T&& v);
|
||||
`
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5474)
|
||||
|
||||
*Constraints*: The call to make_optional does not use
|
||||
an explicit [*template-argument-list*](temp.names#nt:template-argument-list "13.3 Names of template specializations [temp.names]") that
|
||||
begins with a type [*template-argument*](temp.names#nt:template-argument "13.3 Names of template specializations [temp.names]")[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5480)
|
||||
|
||||
*Returns*: optional<decay_t<T>>(std::forward<T>(v))[.](#4.sentence-1)
|
||||
|
||||
[ð](#lib:make_optional_)
|
||||
|
||||
`template<class T, class...Args>
|
||||
constexpr optional<T> make_optional(Args&&... args);
|
||||
`
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5492)
|
||||
|
||||
*Effects*: Equivalent to: return optional<T>(in_place, std::forward<Args>(args)...);
|
||||
|
||||
[ð](#lib:make_optional__)
|
||||
|
||||
`template<class T, class U, class... Args>
|
||||
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
|
||||
`
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5504)
|
||||
|
||||
*Effects*: Equivalent to: return optional<T>(in_place, il, std::forward<Args>(args)...);
|
||||
63
cppdraft/optional/swap.md
Normal file
63
cppdraft/optional/swap.md
Normal file
@@ -0,0 +1,63 @@
|
||||
[optional.swap]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#swap)
|
||||
|
||||
### 22.5.3 Class template optional [[optional.optional]](optional.optional#optional.swap)
|
||||
|
||||
#### 22.5.3.5 Swap [optional.swap]
|
||||
|
||||
[ð](#lib:swap,optional)
|
||||
|
||||
`constexpr void swap(optional& rhs) noexcept(see below);
|
||||
`
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L3999)
|
||||
|
||||
*Mandates*: is_move_constructible_v<T> is true[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4003)
|
||||
|
||||
*Preconditions*: T meets the [*Cpp17Swappable*](swappable.requirements#:Cpp17Swappable "16.4.4.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements"))[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4007)
|
||||
|
||||
*Effects*: See Table [71](#tab:optional.swap "Table 71: optional::swap(optional&) effects")[.](#3.sentence-1)
|
||||
|
||||
Table [71](#tab:optional.swap) — optional::swap(optional&) effects [[tab:optional.swap]](./tab:optional.swap)
|
||||
|
||||
| [ð](#tab:optional.swap-row-1) | | ***this contains a value** | ***this does not contain a value** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:optional.swap-row-2)<br>**rhs contains a value** | | calls swap(*(*this), *rhs) | direct-non-list-initializes the contained value of *this with std::move(*rhs), followed by rhs.val->T::~T(); postcondition is that *this contains a value and rhs does not contain a value |
|
||||
| [ð](#tab:optional.swap-row-3)<br>**rhs does not contain a value** | | direct-non-list-initializes the contained value of rhs with std::move(*(*this)), followed by val->T::~T(); postcondition is that *this does not contain a value and rhs contains a value | no effect |
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4030)
|
||||
|
||||
*Throws*: Any exceptions thrown by the operations in the relevant part of Table [71](#tab:optional.swap "Table 71: optional::swap(optional&) effects")[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4034)
|
||||
|
||||
*Remarks*: The exception specification is equivalent to:is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L4041)
|
||||
|
||||
If any exception is thrown, the results of the expressions this->has_value() and rhs.has_value() remain unchanged[.](#6.sentence-1)
|
||||
|
||||
If an exception is thrown during the call to function swap,
|
||||
the state of *val and *rhs.val is determined by the exception safety guarantee of swap for lvalues of T[.](#6.sentence-2)
|
||||
|
||||
If an exception is thrown during the call to T's move constructor,
|
||||
the state of *val and *rhs.val is determined by the exception safety guarantee of T's move constructor[.](#6.sentence-3)
|
||||
11
cppdraft/optional/syn.md
Normal file
11
cppdraft/optional/syn.md
Normal file
@@ -0,0 +1,11 @@
|
||||
[optional.syn]
|
||||
|
||||
# 22 General utilities library [[utilities]](./#utilities)
|
||||
|
||||
## 22.5 Optional objects [[optional]](optional#syn)
|
||||
|
||||
### 22.5.2 Header <optional> synopsis [optional.syn]
|
||||
|
||||
[ð](#header:%3coptional%3e)
|
||||
|
||||
// mostly freestanding#include <compare> // see [[compare.syn]](compare.syn "17.12.1 Header <compare> synopsis")namespace std {// [[optional.optional]](optional.optional "22.5.3 Class template optional"), class template optionaltemplate<class T>class optional; // partially freestanding// [[optional.optional.ref]](optional.optional.ref "22.5.4 Partial specialization of optional for reference types"), partial specialization of optional for lvalue reference typestemplate<class T>class optional<T&>; // partially freestandingtemplate<class T>constexpr bool ranges::enable_view<optional<T>> = true; template<class T>constexpr auto format_kind<optional<T>> = range_format::disabled; template<class T>constexpr bool ranges::enable_borrowed_range<optional<T&>> = true; template<class T>concept [*is-derived-from-optional*](#concept:is-derived-from-optional "22.5.2 Header <optional> synopsis [optional.syn]") = requires(const T& t) { // *exposition only*[]<class U>(const optional<U>&){ }(t); }; // [[optional.nullopt]](optional.nullopt "22.5.5 No-value state indicator"), no-value state indicatorstruct nullopt_t{*see below*}; inline constexpr nullopt_t nullopt(*unspecified*); // [[optional.bad.access]](optional.bad.access "22.5.6 Class bad_optional_access"), class bad_optional_accessclass bad_optional_access; // [[optional.relops]](optional.relops "22.5.7 Relational operators"), relational operatorstemplate<class T, class U>constexpr bool operator==(const optional<T>&, const optional<U>&); template<class T, class U>constexpr bool operator!=(const optional<T>&, const optional<U>&); template<class T, class U>constexpr bool operator<(const optional<T>&, const optional<U>&); template<class T, class U>constexpr bool operator>(const optional<T>&, const optional<U>&); template<class T, class U>constexpr bool operator<=(const optional<T>&, const optional<U>&); template<class T, class U>constexpr bool operator>=(const optional<T>&, const optional<U>&); template<class T, [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "17.12.4 Concept three_way_comparable [cmp.concept]")<T> U>constexpr compare_three_way_result_t<T, U>operator<=>(const optional<T>&, const optional<U>&); // [[optional.nullops]](optional.nullops "22.5.8 Comparison with nullopt"), comparison with nullopttemplate<class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept; template<class T>constexpr strong_ordering operator<=>(const optional<T>&, nullopt_t) noexcept; // [[optional.comp.with.t]](optional.comp.with.t "22.5.9 Comparison with T"), comparison with Ttemplate<class T, class U> constexpr bool operator==(const optional<T>&, const U&); template<class T, class U> constexpr bool operator==(const T&, const optional<U>&); template<class T, class U> constexpr bool operator!=(const optional<T>&, const U&); template<class T, class U> constexpr bool operator!=(const T&, const optional<U>&); template<class T, class U> constexpr bool operator<(const optional<T>&, const U&); template<class T, class U> constexpr bool operator<(const T&, const optional<U>&); template<class T, class U> constexpr bool operator>(const optional<T>&, const U&); template<class T, class U> constexpr bool operator>(const T&, const optional<U>&); template<class T, class U> constexpr bool operator<=(const optional<T>&, const U&); template<class T, class U> constexpr bool operator<=(const T&, const optional<U>&); template<class T, class U> constexpr bool operator>=(const optional<T>&, const U&); template<class T, class U> constexpr bool operator>=(const T&, const optional<U>&); template<class T, class U>requires (<U>) && [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "17.12.4 Concept three_way_comparable [cmp.concept]")<T, U>constexpr compare_three_way_result_t<T, U>operator<=>(const optional<T>&, const U&); // [[optional.specalg]](optional.specalg "22.5.10 Specialized algorithms"), specialized algorithmstemplate<class T>constexpr void swap(optional<T>&, optional<T>&) noexcept(*see below*); template<class T>constexpr optional<decay_t<T>> make_optional(T&&); template<class T, class... Args>constexpr optional<T> make_optional(Args&&... args); template<class T, class U, class... Args>constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args); // [[optional.hash]](optional.hash "22.5.11 Hash support"), hash supporttemplate<class T> struct hash; template<class T> struct hash<optional<T>>;}
|
||||
Reference in New Issue
Block a user