xref: /llvm-project/libcxx/test/std/utilities/expected/expected.unexpected/assign/assign.move.pass.cpp (revision 6a54dfbfe534276d644d7f9c027f0deeb748dd53)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10 
11 // constexpr unexpected& operator=(unexpected&&) = default;
12 
13 #include <cassert>
14 #include <expected>
15 #include <utility>
16 
17 struct Error {
18   int i;
19   constexpr Error(int ii) : i(ii) {}
20   constexpr Error& operator=(Error&& other) {
21     i       = other.i;
22     other.i = 0;
23     return *this;
24   }
25 };
26 
27 constexpr bool test() {
28   std::unexpected<Error> unex1(4);
29   std::unexpected<Error> unex2(5);
30   unex1 = std::move(unex2);
31   assert(unex1.error().i == 5);
32   assert(unex2.error().i == 0);
33   return true;
34 }
35 
36 int main(int, char**) {
37   test();
38   static_assert(test());
39   return 0;
40 }
41