| 93 | } |
| 94 | |
| 95 | void future_test::test_promise() |
| 96 | { |
| 97 | std::promise<int> p1{}; |
| 98 | test("default constructed promise has state", p1.__state()); |
| 99 | |
| 100 | std::promise<int> p2{}; |
| 101 | auto* s1 = p1.__state(); |
| 102 | auto* s2 = p2.__state(); |
| 103 | p2.swap(p1); |
| 104 | std::swap(s1, s2); |
| 105 | |
| 106 | test_eq("swap switches states pt1", s1, p1.__state()); |
| 107 | test_eq("swap switches states pt2", s2, p2.__state()); |
| 108 | |
| 109 | std::promise<int> p3{std::move(p1)}; |
| 110 | test_eq("move construction state moved", s1, p3.__state()); |
| 111 | test_eq("move construction source empty", p1.__state(), nullptr); |
| 112 | |
| 113 | p1 = std::move(p3); |
| 114 | test_eq("move assignment state move", s1, p1.__state()); |
| 115 | test_eq("move assignment source empty", p3.__state(), nullptr); |
| 116 | |
| 117 | p1.set_value(42); |
| 118 | test("set_value marks state as ready", s1->is_set()); |
| 119 | test_eq("set_value sets value", s1->get(), 42); |
| 120 | } |
| 121 | |
| 122 | void future_test::test_future_promise() |
| 123 | { |