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

source code of libcxx/test/std/ranges/range.adaptors/range.common.view/end.pass.cpp