From Jason Turner

[expected.void.monadic]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpozhnkjux/{from.md → to.md} +184 -0
tmp/tmpozhnkjux/{from.md → to.md} RENAMED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Monadic operations <a id="expected.void.monadic">[[expected.void.monadic]]</a>
2
+
3
+ ``` cpp
4
+ template<class F> constexpr auto and_then(F&& f) &;
5
+ template<class F> constexpr auto and_then(F&& f) const &;
6
+ ```
7
+
8
+ Let `U` be `remove_cvref_t<invoke_result_t<F>>`.
9
+
10
+ *Constraints:* `is_constructible_v<E, decltype(error())>>` is `true`.
11
+
12
+ *Mandates:* `U` is a specialization of `expected` and
13
+ `is_same_v<U::error_type, E>` is `true`.
14
+
15
+ *Effects:* Equivalent to:
16
+
17
+ ``` cpp
18
+ if (has_value())
19
+ return invoke(std::forward<F>(f));
20
+ else
21
+ return U(unexpect, error());
22
+ ```
23
+
24
+ ``` cpp
25
+ template<class F> constexpr auto and_then(F&& f) &&;
26
+ template<class F> constexpr auto and_then(F&& f) const &&;
27
+ ```
28
+
29
+ Let `U` be `remove_cvref_t<invoke_result_t<F>>`.
30
+
31
+ *Constraints:* `is_constructible_v<E, decltype(std::move(error()))>` is
32
+ `true`.
33
+
34
+ *Mandates:* `U` is a specialization of `expected` and
35
+ `is_same_v<U::error_type, E>` is `true`.
36
+
37
+ *Effects:* Equivalent to:
38
+
39
+ ``` cpp
40
+ if (has_value())
41
+ return invoke(std::forward<F>(f));
42
+ else
43
+ return U(unexpect, std::move(error()));
44
+ ```
45
+
46
+ ``` cpp
47
+ template<class F> constexpr auto or_else(F&& f) &;
48
+ template<class F> constexpr auto or_else(F&& f) const &;
49
+ ```
50
+
51
+ Let `G` be `remove_cvref_t<invoke_result_t<F, decltype(error())>>`.
52
+
53
+ *Mandates:* `G` is a specialization of `expected` and
54
+ `is_same_v<G::value_type, T>` is `true`.
55
+
56
+ *Effects:* Equivalent to:
57
+
58
+ ``` cpp
59
+ if (has_value())
60
+ return G();
61
+ else
62
+ return invoke(std::forward<F>(f), error());
63
+ ```
64
+
65
+ ``` cpp
66
+ template<class F> constexpr auto or_else(F&& f) &&;
67
+ template<class F> constexpr auto or_else(F&& f) const &&;
68
+ ```
69
+
70
+ Let `G` be
71
+ `remove_cvref_t<invoke_result_t<F, decltype(std::move(error()))>>`.
72
+
73
+ *Mandates:* `G` is a specialization of `expected` and
74
+ `is_same_v<G::value_type, T>` is `true`.
75
+
76
+ *Effects:* Equivalent to:
77
+
78
+ ``` cpp
79
+ if (has_value())
80
+ return G();
81
+ else
82
+ return invoke(std::forward<F>(f), std::move(error()));
83
+ ```
84
+
85
+ ``` cpp
86
+ template<class F> constexpr auto transform(F&& f) &;
87
+ template<class F> constexpr auto transform(F&& f) const &;
88
+ ```
89
+
90
+ Let `U` be `remove_cv_t<invoke_result_t<F>>`.
91
+
92
+ *Constraints:* `is_constructible_v<E, decltype(error())>` is `true`.
93
+
94
+ *Mandates:* `U` is a valid value type for `expected`. If `is_void_v<U>`
95
+ is `false`, the declaration
96
+
97
+ ``` cpp
98
+ U u(invoke(std::forward<F>(f)));
99
+ ```
100
+
101
+ is well-formed.
102
+
103
+ *Effects:*
104
+
105
+ - If `has_value()` is `false`, returns
106
+ `expected<U, E>(unexpect, error())`.
107
+ - Otherwise, if `is_void_v<U>` is `false`, returns an `expected<U, E>`
108
+ object whose *has_val* member is `true` and *val* member is
109
+ direct-non-list-initialized with `invoke(std::forward<F>(f))`.
110
+ - Otherwise, evaluates `invoke(std::forward<F>(f))` and then returns
111
+ `expected<U, E>()`.
112
+
113
+ ``` cpp
114
+ template<class F> constexpr auto transform(F&& f) &&;
115
+ template<class F> constexpr auto transform(F&& f) const &&;
116
+ ```
117
+
118
+ Let `U` be `remove_cv_t<invoke_result_t<F>>`.
119
+
120
+ *Constraints:* `is_constructible_v<E, decltype(std::move(error()))>` is
121
+ `true`.
122
+
123
+ *Mandates:* `U` is a valid value type for `expected`. If `is_void_v<U>`
124
+ is `false`, the declaration
125
+
126
+ ``` cpp
127
+ U u(invoke(std::forward<F>(f)));
128
+ ```
129
+
130
+ is well-formed.
131
+
132
+ *Effects:*
133
+
134
+ - If `has_value()` is `false`, returns
135
+ `expected<U, E>(unexpect, std::move(error()))`.
136
+ - Otherwise, if `is_void_v<U>` is `false`, returns an `expected<U, E>`
137
+ object whose *has_val* member is `true` and *val* member is
138
+ direct-non-list-initialized with `invoke(std::forward<F>(f))`.
139
+ - Otherwise, evaluates `invoke(std::forward<F>(f))` and then returns
140
+ `expected<U, E>()`.
141
+
142
+ ``` cpp
143
+ template<class F> constexpr auto transform_error(F&& f) &;
144
+ template<class F> constexpr auto transform_error(F&& f) const &;
145
+ ```
146
+
147
+ Let `G` be `remove_cv_t<invoke_result_t<F, decltype(error())>>`.
148
+
149
+ *Mandates:* `G` is a valid template argument for `unexpected`
150
+ [[expected.un.general]] and the declaration
151
+
152
+ ``` cpp
153
+ G g(invoke(std::forward<F>(f), error()));
154
+ ```
155
+
156
+ is well-formed.
157
+
158
+ *Returns:* If `has_value()` is `true`, `expected<T, G>()`; otherwise, an
159
+ `expected<T, G>` object whose *has_val* member is `false` and *unex*
160
+ member is direct-non-list-initialized with
161
+ `invoke(std::forward<F>(f), error())`.
162
+
163
+ ``` cpp
164
+ template<class F> constexpr auto transform_error(F&& f) &&;
165
+ template<class F> constexpr auto transform_error(F&& f) const &&;
166
+ ```
167
+
168
+ Let `G` be
169
+ `remove_cv_t<invoke_result_t<F, decltype(std::move(error()))>>`.
170
+
171
+ *Mandates:* `G` is a valid template argument for `unexpected`
172
+ [[expected.un.general]] and the declaration
173
+
174
+ ``` cpp
175
+ G g(invoke(std::forward<F>(f), std::move(error())));
176
+ ```
177
+
178
+ is well-formed.
179
+
180
+ *Returns:* If `has_value()` is `true`, `expected<T, G>()`; otherwise, an
181
+ `expected<T, G>` object whose *has_val* member is `false` and *unex*
182
+ member is direct-non-list-initialized with
183
+ `invoke(std::forward<F>(f), std::move(error()))`.
184
+