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