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// Check constraints on the type itself.
14//
15// template <forward_range View, indirect_binary_predicate<iterator_t<View>, iterator_t<View>> Pred>
16// requires view<View> && is_object_v<Pred>
17// class chunk_by_view;
18
19#include <ranges>
20
21#include <concepts>
22#include <cstddef>
23#include <iterator>
24#include <type_traits>
25
26#include "almost_satisfies_types.h"
27#include "test_iterators.h"
28
29template <class View, class Pred>
30concept CanFormChunkByView = requires { typename std::ranges::chunk_by_view<View, Pred>; };
31
32// chunk_by_view is not valid when the view is not a forward_range
33namespace test_when_view_is_not_a_forward_range {
34
35struct View : std::ranges::view_base {
36 ForwardIteratorNotDerivedFrom begin() const;
37 ForwardIteratorNotDerivedFrom end() const;
38};
39struct Pred {
40 bool operator()(int, int) const;
41};
42
43static_assert(!std::ranges::forward_range<View>);
44static_assert(std::indirect_binary_predicate<Pred, int*, int*>);
45static_assert(std::ranges::view<View>);
46static_assert(std::is_object_v<Pred>);
47static_assert(!CanFormChunkByView<View, Pred>);
48
49} // namespace test_when_view_is_not_a_forward_range
50
51// chunk_by_view is not valid when the predicate is not indirect_binary_predicate
52namespace test_when_the_predicate_is_not_indirect_binary_predicate {
53
54struct View : std::ranges::view_base {
55 int* begin() const;
56 int* end() const;
57};
58struct Pred {};
59
60static_assert(std::ranges::forward_range<View>);
61static_assert(!std::indirect_binary_predicate<Pred, int*, int*>);
62static_assert(std::ranges::view<View>);
63static_assert(std::is_object_v<Pred>);
64static_assert(!CanFormChunkByView<View, Pred>);
65
66} // namespace test_when_the_predicate_is_not_indirect_binary_predicate
67
68// chunk_by_view is not valid when the view is not a view
69namespace test_when_the_view_param_is_not_a_view {
70
71struct View {
72 int* begin() const;
73 int* end() const;
74};
75struct Pred {
76 bool operator()(int, int) const;
77};
78
79static_assert(std::ranges::input_range<View>);
80static_assert(std::indirect_binary_predicate<Pred, int*, int*>);
81static_assert(!std::ranges::view<View>);
82static_assert(std::is_object_v<Pred>);
83static_assert(!CanFormChunkByView<View, Pred>);
84
85} // namespace test_when_the_view_param_is_not_a_view
86
87// chunk_by_view is not valid when the predicate is not an object type
88namespace test_when_the_predicate_is_not_an_object_type {
89
90struct View : std::ranges::view_base {
91 int* begin() const;
92 int* end() const;
93};
94using Pred = bool (&)(int, int);
95
96static_assert(std::ranges::input_range<View>);
97static_assert(std::indirect_binary_predicate<Pred, int*, int*>);
98static_assert(std::ranges::view<View>);
99static_assert(!std::is_object_v<Pred>);
100static_assert(!CanFormChunkByView<View, Pred>);
101
102} // namespace test_when_the_predicate_is_not_an_object_type
103
104// chunk_by_view is valid when all the constraints are satisfied (test the test)
105namespace test_when_all_the_constraints_are_satisfied {
106
107struct View : std::ranges::view_base {
108 int* begin() const;
109 int* end() const;
110};
111struct Pred {
112 bool operator()(int, int) const;
113};
114
115static_assert(std::ranges::input_range<View>);
116static_assert(std::indirect_binary_predicate<Pred, int*, int*>);
117static_assert(std::ranges::view<View>);
118static_assert(std::is_object_v<Pred>);
119static_assert(CanFormChunkByView<View, Pred>);
120
121} // namespace test_when_all_the_constraints_are_satisfied
122

source code of libcxx/test/std/ranges/range.adaptors/range.chunk.by/constraints.compile.pass.cpp