From Jason Turner

[expected.object.swap]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp9e9my7zr/{from.md → to.md} +69 -0
tmp/tmp9e9my7zr/{from.md → to.md} RENAMED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Swap <a id="expected.object.swap">[[expected.object.swap]]</a>
2
+
3
+ ``` cpp
4
+ constexpr void swap(expected& rhs) noexcept(see below);
5
+ ```
6
+
7
+ *Constraints:*
8
+
9
+ - `is_swappable_v<T>` is `true` and
10
+ - `is_swappable_v<E>` is `true` and
11
+ - `is_move_constructible_v<T> && is_move_constructible_v<E>` is `true`,
12
+ and
13
+ - `is_nothrow_move_constructible_v<T> || is_nothrow_move_constructible_v<E>`
14
+ is `true`.
15
+
16
+ *Effects:* See [[expected.object.swap]].
17
+
18
+ **Table: `swap(expected&)` effects** <a id="expected.object.swap">[expected.object.swap]</a>
19
+
20
+ | \topline | `this->has_value()` | `!this->has_value()` |
21
+ | -------- | ------------------- | -------------------- |
22
+
23
+
24
+ For the case where `rhs.value()` is `false` and `this->has_value()` is
25
+ `true`, equivalent to:
26
+
27
+ ``` cpp
28
+ if constexpr (is_nothrow_move_constructible_v<E>) {
29
+ E tmp(std::move(rhs.unex));
30
+ destroy_at(addressof(rhs.unex));
31
+ try {
32
+ construct_at(addressof(rhs.val), std::move(val));
33
+ destroy_at(addressof(val));
34
+ construct_at(addressof(unex), std::move(tmp));
35
+ } catch(...) {
36
+ construct_at(addressof(rhs.unex), std::move(tmp));
37
+ throw;
38
+ }
39
+ } else {
40
+ T tmp(std::move(val));
41
+ destroy_at(addressof(val));
42
+ try {
43
+ construct_at(addressof(unex), std::move(rhs.unex));
44
+ destroy_at(addressof(rhs.unex));
45
+ construct_at(addressof(rhs.val), std::move(tmp));
46
+ } catch (...) {
47
+ construct_at(addressof(val), std::move(tmp));
48
+ throw;
49
+ }
50
+ }
51
+ has_val = false;
52
+ rhs.has_val = true;
53
+ ```
54
+
55
+ *Throws:* Any exception thrown by the expressions in the *Effects*.
56
+
57
+ *Remarks:* The exception specification is equivalent to:
58
+
59
+ ``` cpp
60
+ is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T> &&
61
+ is_nothrow_move_constructible_v<E> && is_nothrow_swappable_v<E>
62
+ ```
63
+
64
+ ``` cpp
65
+ friend constexpr void swap(expected& x, expected& y) noexcept(noexcept(x.swap(y)));
66
+ ```
67
+
68
+ *Effects:* Equivalent to `x.swap(y)`.
69
+