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