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 reverse_iterator<iterator_t<V>> end();
12// constexpr auto end() const requires common_range<const V>;
13
14#include <ranges>
15
16#include <cassert>
17#include <utility>
18
19#include "test_macros.h"
20#include "types.h"
21
22constexpr bool test() {
23 int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
24
25 // Common bidirectional range.
26 {
27 auto rev = std::ranges::reverse_view(BidirRange{buffer, buffer + 8});
28 assert(base(rev.end().base()) == buffer);
29 assert(base(std::move(rev).end().base()) == buffer);
30
31 ASSERT_SAME_TYPE(decltype(rev.end()), std::reverse_iterator<bidirectional_iterator<int*>>);
32 ASSERT_SAME_TYPE(decltype(std::move(rev).end()), std::reverse_iterator<bidirectional_iterator<int*>>);
33 }
34 // Const common bidirectional range.
35 {
36 const auto rev = std::ranges::reverse_view(BidirRange{buffer, buffer + 8});
37 assert(base(rev.end().base()) == buffer);
38 assert(base(std::move(rev).end().base()) == buffer);
39
40 ASSERT_SAME_TYPE(decltype(rev.end()), std::reverse_iterator<bidirectional_iterator<const int*>>);
41 ASSERT_SAME_TYPE(decltype(std::move(rev).end()), std::reverse_iterator<bidirectional_iterator<const int*>>);
42 }
43 // Non-common, non-const (move only) bidirectional range.
44 {
45 auto rev = std::ranges::reverse_view(BidirSentRange<MoveOnly>{buffer, buffer + 8});
46 assert(base(std::move(rev).end().base()) == buffer);
47
48 ASSERT_SAME_TYPE(decltype(std::move(rev).end()), std::reverse_iterator<bidirectional_iterator<int*>>);
49 }
50 // Non-common, const bidirectional range.
51 {
52 auto rev = std::ranges::reverse_view(BidirSentRange<Copyable>{buffer, buffer + 8});
53 assert(base(rev.end().base()) == buffer);
54 assert(base(std::move(rev).end().base()) == buffer);
55
56 ASSERT_SAME_TYPE(decltype(rev.end()), std::reverse_iterator<bidirectional_iterator<int*>>);
57 ASSERT_SAME_TYPE(decltype(std::move(rev).end()), std::reverse_iterator<bidirectional_iterator<int*>>);
58 }
59
60 return true;
61}
62
63int main(int, char**) {
64 test();
65 static_assert(test());
66
67 return 0;
68}
69

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