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

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