From Jason Turner

[optional.ref.monadic]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpo6syl047/{from.md → to.md} +61 -0
tmp/tmpo6syl047/{from.md → to.md} RENAMED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Monadic operations <a id="optional.ref.monadic">[[optional.ref.monadic]]</a>
2
+
3
+ ``` cpp
4
+ template<class F> constexpr auto and_then(F&& f) const;
5
+ ```
6
+
7
+ Let `U` be `invoke_result_t<F, T&>`.
8
+
9
+ *Mandates:* `remove_cvref_t<U>` is a specialization of `optional`.
10
+
11
+ *Effects:* Equivalent to:
12
+
13
+ ``` cpp
14
+ if (has_value()) {
15
+ return invoke(std::forward<F>(f), *val);
16
+ } else {
17
+ return remove_cvref_t<U>();
18
+ }
19
+ ```
20
+
21
+ ``` cpp
22
+ template<class F>
23
+ constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
24
+ ```
25
+
26
+ Let `U` be `remove_cv_t<invoke_result_t<F, T&>>`.
27
+
28
+ *Mandates:* The declaration
29
+
30
+ ``` cpp
31
+ U u(invoke(std::forward<F>(f), *val));
32
+ ```
33
+
34
+ is well-formed for some invented variable `u`.
35
+
36
+ [*Note 1*: There is no requirement that `U` is
37
+ movable [[dcl.init.general]]. — *end note*]
38
+
39
+ *Returns:* If `*this` contains a value, an `optional<U>` object whose
40
+ contained value is direct-non-list-initialized with
41
+ `invoke(std::forward<F>(f), *`*`val`*`)`; otherwise, `optional<U>()`.
42
+
43
+ ``` cpp
44
+ template<class F> constexpr optional or_else(F&& f) const;
45
+ ```
46
+
47
+ *Constraints:* `F` models `invocable`.
48
+
49
+ *Mandates:* `is_same_v<remove_cvref_t<invoke_result_t<F>>, optional>` is
50
+ `true`.
51
+
52
+ *Effects:* Equivalent to:
53
+
54
+ ``` cpp
55
+ if (has_value()) {
56
+ return *val;
57
+ } else {
58
+ return std::forward<F>(f)();
59
+ }
60
+ ```
61
+