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 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
11
12 // constexpr auto end();
13 // constexpr auto end() const requires range<const V>;
14
15 #include <ranges>
16
17 #include <cassert>
18 #include <concepts>
19 #include <utility>
20
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 #include "types.h"
24
test()25 constexpr bool test() {
26 int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
27
28 {
29 SizedRandomAccessView view{buf, buf + 8};
30 std::ranges::common_view<SizedRandomAccessView> common(view);
31 std::same_as<RandomAccessIter> auto end = common.end(); // Note this should NOT be the sentinel type.
32 assert(base(end) == buf + 8);
33 }
34
35 // const version
36 {
37 SizedRandomAccessView view{buf, buf + 8};
38 std::ranges::common_view<SizedRandomAccessView> const common(view);
39 std::same_as<RandomAccessIter> auto end = common.end(); // Note this should NOT be the sentinel type.
40 assert(base(end) == buf + 8);
41 }
42
43 return true;
44 }
45
main(int,char **)46 int main(int, char**) {
47 test();
48 static_assert(test());
49
50 {
51 int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8};
52
53 using CommonForwardIter = std::common_iterator<ForwardIter, sized_sentinel<ForwardIter>>;
54 using CommonIntIter = std::common_iterator<int*, sentinel_wrapper<int*>>;
55
56 {
57 SizedForwardView view{buf, buf + 8};
58 std::ranges::common_view<SizedForwardView> common(view);
59 std::same_as<CommonForwardIter> auto end = common.end();
60 assert(end == CommonForwardIter(std::ranges::end(view)));
61 }
62 {
63 CopyableView view{buf, buf + 8};
64 std::ranges::common_view<CopyableView> common(view);
65 std::same_as<CommonIntIter> auto end = common.end();
66 assert(end == CommonIntIter(std::ranges::end(view)));
67 }
68
69 // const versions
70 {
71 SizedForwardView view{buf, buf + 8};
72 std::ranges::common_view<SizedForwardView> const common(view);
73 std::same_as<CommonForwardIter> auto end = common.end();
74 assert(end == CommonForwardIter(std::ranges::end(view)));
75 }
76 {
77 CopyableView view{buf, buf + 8};
78 std::ranges::common_view<CopyableView> const common(view);
79 std::same_as<CommonIntIter> auto end = common.end();
80 assert(end == CommonIntIter(std::ranges::end(view)));
81 }
82 }
83
84 return 0;
85 }
86