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 | // constexpr explicit move_sentinel(S s); |
16 | |
17 | #include <cassert> |
18 | #include <iterator> |
19 | #include <type_traits> |
20 | |
21 | constexpr bool test() |
22 | { |
23 | // The underlying sentinel is an integer. |
24 | { |
25 | static_assert(!std::is_convertible_v<int, std::move_sentinel<int>>); |
26 | std::move_sentinel<int> m(42); |
27 | assert(m.base() == 42); |
28 | } |
29 | |
30 | // The underlying sentinel is a pointer. |
31 | { |
32 | static_assert(!std::is_convertible_v<int*, std::move_sentinel<int*>>); |
33 | int i = 42; |
34 | std::move_sentinel<int*> m(&i); |
35 | assert(m.base() == &i); |
36 | } |
37 | |
38 | // The underlying sentinel is a user-defined type with an explicit default constructor. |
39 | { |
40 | struct S { |
41 | explicit S() = default; |
42 | constexpr explicit S(int j) : i(j) {} |
43 | int i = 3; |
44 | }; |
45 | static_assert(!std::is_convertible_v<S, std::move_sentinel<S>>); |
46 | std::move_sentinel<S> m(S(42)); |
47 | assert(m.base().i == 42); |
48 | } |
49 | return true; |
50 | } |
51 | |
52 | int main(int, char**) |
53 | { |
54 | test(); |
55 | static_assert(test()); |
56 | |
57 | return 0; |
58 | } |
59 | |