From Jason Turner

[expected.object.monadic]

Diff to HTML by rtfpessoa

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