xref: /llvm-project/libcxx/test/std/iterators/predef.iterators/move.iterators/move.sentinel/base.pass.cpp (revision b06049bc3b79be4a037a60dec4ad19a68e196a8f)
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 S base() const;
16 
17 #include <cassert>
18 #include <iterator>
19 #include <utility>
20 
21 #include "test_macros.h"
22 
test()23 constexpr bool test()
24 {
25   // The sentinel type is a value.
26   {
27     auto m = std::move_sentinel<int>(42);
28     const auto& cm = m;
29     assert(m.base() == 42);
30     assert(cm.base() == 42);
31     assert(std::move(m).base() == 42);
32     assert(std::move(cm).base() == 42);
33     ASSERT_SAME_TYPE(decltype(m.base()), int);
34     ASSERT_SAME_TYPE(decltype(cm.base()), int);
35     ASSERT_SAME_TYPE(decltype(std::move(m).base()), int);
36     ASSERT_SAME_TYPE(decltype(std::move(cm).base()), int);
37   }
38 
39   // The sentinel type is a pointer.
40   {
41     int a[] = {1, 2, 3};
42     auto m = std::move_sentinel<const int*>(a);
43     const auto& cm = m;
44     assert(m.base() == a);
45     assert(cm.base() == a);
46     assert(std::move(m).base() == a);
47     assert(std::move(cm).base() == a);
48     ASSERT_SAME_TYPE(decltype(m.base()), const int*);
49     ASSERT_SAME_TYPE(decltype(cm.base()), const int*);
50     ASSERT_SAME_TYPE(decltype(std::move(m).base()), const int*);
51     ASSERT_SAME_TYPE(decltype(std::move(cm).base()), const int*);
52   }
53   return true;
54 }
55 
main(int,char **)56 int main(int, char**)
57 {
58   test();
59   static_assert(test());
60 
61   return 0;
62 }
63