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