Debian Codegraph @

libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/deref.pass.cpp

raw
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, c++20
10
11 // <ranges>
12
13 // constexpr value_type operator*() const;
14
15 #include <ranges>
16
17 #include <algorithm>
18 #include <array>
19 #include <cassert>
20 #include <concepts>
21 #include <functional>
22 #include <utility>
23
24 #include "../types.h"
25 #include "test_iterators.h"
26 #include "test_macros.h"
27
28 template <class Iter, class Sent = sentinel_wrapper<Iter>>
29 constexpr void test() {
30 using Underlying = View<Iter, Sent>;
31 using ChunkByView = std::ranges::chunk_by_view<Underlying, std::ranges::less_equal>;
32 using ChunkByIterator = std::ranges::iterator_t<ChunkByView>;
33
34 std::array array{0, 1, 2, 3, -1, 0, 1, 2, -2, 3, 4, 5};
35 std::array expected{std::array{0, 1, 2, 3}, std::array{-1, 0, 1, 2}, std::array{-2, 3, 4, 5}};
36 Underlying underlying{Iter{array.data()}, Sent{Iter{array.data() + array.size()}}};
37 ChunkByView view{underlying, std::ranges::less_equal{}};
38
39 size_t idx = 0;
40 for (std::same_as<ChunkByIterator> auto iter = view.begin(); iter != view.end(); ++idx, ++iter) {
41 std::same_as<typename ChunkByIterator::value_type> auto chunk = *iter;
42 assert(std::ranges::equal(chunk, expected[idx]));
43 }
44 }
45
46 constexpr bool tests() {
47 // Check iterator-sentinel pair
48 test<forward_iterator<int*>>();
49 test<bidirectional_iterator<int*>>();
50 test<random_access_iterator<int*>>();
51 test<contiguous_iterator<int*>>();
52 test<int*>();
53
54 // Check iterator pair
55 test<forward_iterator<int*>, forward_iterator<int*>>();
56 test<bidirectional_iterator<int*>, bidirectional_iterator<int*>>();
57 test<random_access_iterator<int*>, random_access_iterator<int*>>();
58 test<contiguous_iterator<int*>, contiguous_iterator<int*>>();
59 test<int*, int*>();
60
61 return true;
62 }
63
64 int main(int, char**) {
65 tests();
66 static_assert(tests());
67
68 return 0;
69 }