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
10
11 // <iterator>
12
13 // move_sentinel
14
15 // template<class S2>
16 // requires assignable_from<S&, const S2&>
17 // constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
18
19 #include <iterator>
20 #include <cassert>
21 #include <concepts>
22
23 struct NonAssignable {
24 NonAssignable& operator=(int i);
25 };
26 static_assert(std::semiregular<NonAssignable>);
27 static_assert(std::is_assignable_v<NonAssignable, int>);
28 static_assert(!std::assignable_from<NonAssignable, int>);
29
test()30 constexpr bool test()
31 {
32 // Assigning from an lvalue.
33 {
34 std::move_sentinel<int> m(42);
35 std::move_sentinel<long> m2;
36 m2 = m;
37 assert(m2.base() == 42L);
38 }
39
40 // Assigning from an rvalue.
41 {
42 std::move_sentinel<long> m2;
43 m2 = std::move_sentinel<int>(43);
44 assert(m2.base() == 43L);
45 }
46
47 // SFINAE checks.
48 {
49 static_assert( std::is_assignable_v<std::move_sentinel<int>, std::move_sentinel<long>>);
50 static_assert(!std::is_assignable_v<std::move_sentinel<int*>, std::move_sentinel<const int*>>);
51 static_assert( std::is_assignable_v<std::move_sentinel<const int*>, std::move_sentinel<int*>>);
52 static_assert(!std::is_assignable_v<std::move_sentinel<NonAssignable>, std::move_sentinel<int>>);
53 }
54 return true;
55 }
56
main(int,char **)57 int main(int, char**)
58 {
59 test();
60 static_assert(test());
61
62 return 0;
63 }
64