Skip to content

Commit 12f36c4

Browse files
committed
repeats for fold_left
1 parent 6a57523 commit 12f36c4

File tree

2 files changed

+202
-99
lines changed

2 files changed

+202
-99
lines changed

libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/fold_left/requirements.compile.pass.cpp

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
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+
// <algorithm>
10+
11+
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
12+
13+
// Checks that `std::ranges::fold_left`'s requirements are correct.
14+
15+
#include <algorithm>
16+
#include <concepts>
17+
#include <functional>
18+
#include <iterator>
19+
#include <ranges>
20+
21+
#include "test_range.h"
22+
#include "test_iterators.h"
23+
#include "../requirements.h"
24+
25+
// expected-error@*:* 19 {{no matching function for call to object of type 'const __fold_left'}}
26+
27+
void test_iterator() {
28+
// expected-note@*:* 10 {{candidate template ignored: constraints not satisfied}}
29+
// expected-note@*:* 10 {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
30+
31+
std::ranges::fold_left(bad_iterator_category(), std::unreachable_sentinel, 0, std::plus());
32+
// expected-note@*:* {{because 'bad_iterator_category' does not satisfy 'input_iterator'}}
33+
// expected-note@*:* {{because 'derived_from<_ITER_CONCEPT<bad_iterator_category>, input_iterator_tag>' evaluated to false}}
34+
// expected-note@*:* {{because 'is_base_of_v<std::input_iterator_tag, void>' evaluated to false}}
35+
36+
{
37+
int* first;
38+
int* last;
39+
std::ranges::fold_left(cpp17_input_iterator<int*>(first), cpp17_input_iterator<int*>(last), 0, std::plus());
40+
// expected-note@*:* {{because 'sentinel_for<cpp17_input_iterator<int *>, cpp17_input_iterator<int *> >' evaluated to false}}
41+
// expected-note@*:* {{because 'cpp17_input_iterator<int *>' does not satisfy 'semiregular'}}
42+
// expected-note@*:* {{'cpp17_input_iterator<int *>' does not satisfy 'default_initializable'}}
43+
// expected-note@*:* {{because 'cpp17_input_iterator<int *>' does not satisfy 'constructible_from'}}
44+
// expected-note@*:* {{because 'is_constructible_v<cpp17_input_iterator<int *> >' evaluated to false}}
45+
46+
std::ranges::fold_left(first, last, 0, non_copy_constructible_callable());
47+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_copy_constructible_callable, int, int *>' evaluated to false}}
48+
// expected-note@*:* {{because 'non_copy_constructible_callable' does not satisfy 'copy_constructible'}}
49+
// expected-note@*:* {{because 'constructible_from<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
50+
// expected-note@*:* {{because 'is_constructible_v<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
51+
52+
std::ranges::fold_left(first, last, 0, not_invocable());
53+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<not_invocable, int, int *>' evaluated to false}}
54+
// expected-note@*:* {{because 'invocable<not_invocable &, int, iter_reference_t<int *> >' evaluated to false}}
55+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
56+
}
57+
{
58+
S* first = nullptr;
59+
S* last = nullptr;
60+
std::ranges::fold_left(first, last, S(), non_decayable_result());
61+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_decayable_result, S, S *>' evaluated to false}}
62+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<non_decayable_result, S, S *, invoke_result_t<non_decayable_result &, S, iter_reference_t<S *> > >' evaluated to false}}
63+
// expected-note@*:* {{because 'convertible_to<volatile S &, S>' evaluated to false}}
64+
// expected-note@*:* {{because 'is_convertible_v<volatile S &, S>' evaluated to false}}
65+
}
66+
{
67+
copyable_non_movable* first;
68+
copyable_non_movable* last;
69+
std::ranges::fold_left(first, last, non_movable(), std::plus());
70+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, non_movable, copyable_non_movable *>' evaluated to false}}
71+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, non_movable, copyable_non_movable *, invoke_result_t<plus<void> &, non_movable, iter_reference_t<copyable_non_movable *> > >' evaluated to false}}
72+
// expected-note@*:* {{because 'non_movable' does not satisfy 'movable'}}
73+
// expected-note@*:* {{because 'non_movable' does not satisfy 'move_constructible'}}
74+
// expected-note@*:* {{because 'constructible_from<non_movable, non_movable>' evaluated to false}}
75+
// expected-note@*:* {{because 'is_constructible_v<non_movable, non_movable>' evaluated to false}}
76+
}
77+
{
78+
copyable_non_movable* first;
79+
copyable_non_movable* last;
80+
std::ranges::fold_left(first, last, 0, std::minus());
81+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::minus<void>, int, copyable_non_movable *>' evaluated to false}}
82+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::minus<void>, int, copyable_non_movable *, invoke_result_t<minus<void> &, int, iter_reference_t<copyable_non_movable *> > >' evaluated to false}}
83+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'movable'}}
84+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'move_constructible'}}
85+
// expected-note@*:* {{because 'constructible_from<copyable_non_movable, copyable_non_movable>' evaluated to false}}
86+
// expected-note@*:* {{because 'is_constructible_v<copyable_non_movable, copyable_non_movable>' evaluated to false}}
87+
}
88+
{
89+
int* first = nullptr;
90+
int* last = nullptr;
91+
std::ranges::fold_left(first, last, not_convertible_to_int(), std::plus());
92+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_convertible_to_int, int *>' evaluated to false}}
93+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_convertible_to_int, int *, invoke_result_t<plus<void> &, not_convertible_to_int, iter_reference_t<int *> > >' evaluated to false}}
94+
// expected-note@*:* {{because 'convertible_to<not_convertible_to_int, int>' evaluated to false}}
95+
// expected-note@*:* {{because 'is_convertible_v<not_convertible_to_int, int>' evaluated to false}}
96+
}
97+
{
98+
not_invocable_with_decayed* first;
99+
not_invocable_with_decayed* last;
100+
std::ranges::fold_left(first, last, 0, std::plus());
101+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, int, not_invocable_with_decayed *>' evaluated to false}}
102+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, int, not_invocable_with_decayed *, invoke_result_t<plus<void> &, int, iter_reference_t<not_invocable_with_decayed *> > >' evaluated to false}}
103+
// expected-note@*:* {{because 'invocable<std::plus<void> &, not_invocable_with_decayed, iter_reference_t<not_invocable_with_decayed *> >' evaluated to false}}
104+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
105+
}
106+
{
107+
not_assignable_to_decayed* first;
108+
not_assignable_to_decayed* last;
109+
std::ranges::fold_left(first, last, not_assignable_to_decayed(), std::plus());
110+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_assignable_to_decayed, not_assignable_to_decayed *>' evaluated to false}}
111+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_assignable_to_decayed, not_assignable_to_decayed *, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<not_assignable_to_decayed *> > >' evaluated to false}}
112+
// expected-note@*:* {{because 'assignable_from<not_assignable_to_decayed &, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<not_assignable_to_decayed *> > >' evaluated to false}}
113+
// expected-note@*:* {{because '__lhs = std::forward<_Rhs>(__rhs)' would be invalid: no viable overloaded '='}}
114+
}
115+
}
116+
117+
void test_fold_range() {
118+
// expected-note@*:* 9 {{candidate template ignored: constraints not satisfied}}
119+
// expected-note@*:* 9 {{candidate function template not viable: requires 4 arguments, but 3 were provided}}
120+
121+
{
122+
struct bad_range {
123+
bad_iterator_category begin();
124+
std::unreachable_sentinel_t end();
125+
};
126+
127+
bad_range r;
128+
std::ranges::fold_left(r, 0, std::plus());
129+
// expected-note@*:* {{because 'bad_range &' does not satisfy 'input_range'}}
130+
// expected-note@*:* {{because 'iterator_t<bad_range &>' (aka 'bad_iterator_category') does not satisfy 'input_iterator'}}
131+
// expected-note@*:* {{because 'derived_from<_ITER_CONCEPT<bad_iterator_category>, input_iterator_tag>' evaluated to false}}
132+
// expected-note@*:* {{because 'is_base_of_v<std::input_iterator_tag, void>' evaluated to false}}
133+
}
134+
{
135+
test_range<cpp20_input_iterator, int> r;
136+
137+
std::ranges::fold_left(r, 0, non_copy_constructible_callable());
138+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_copy_constructible_callable, int, iterator_t<test_range<cpp20_input_iterator, int> &> >' evaluated to false}}
139+
// expected-note@*:* {{because 'non_copy_constructible_callable' does not satisfy 'copy_constructible'}}
140+
// expected-note@*:* {{because 'constructible_from<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
141+
// expected-note@*:* {{because 'is_constructible_v<non_copy_constructible_callable, non_copy_constructible_callable &>' evaluated to false}}
142+
143+
std::ranges::fold_left(r, 0, not_invocable());
144+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<not_invocable, int, iterator_t<test_range<cpp20_input_iterator, int> &> >' evaluated to false}}
145+
// expected-note@*:* {{because 'invocable<not_invocable &, int, iter_reference_t<cpp20_input_iterator<int *> > >' evaluated to false}}
146+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
147+
}
148+
{
149+
test_range<cpp20_input_iterator, S> r;
150+
151+
std::ranges::fold_left(r, S(), non_decayable_result());
152+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<non_decayable_result, S, iterator_t<test_range<cpp20_input_iterator, S> &> >' evaluated to false}}
153+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<non_decayable_result, S, cpp20_input_iterator<S *>, invoke_result_t<non_decayable_result &, S, iter_reference_t<cpp20_input_iterator<S *> > > >' evaluated to false}}
154+
// expected-note@*:* {{because 'convertible_to<volatile S &, S>' evaluated to false}}
155+
// expected-note@*:* {{because 'is_convertible_v<volatile S &, S>' evaluated to false}}
156+
}
157+
{
158+
test_range<cpp20_input_iterator, copyable_non_movable> r;
159+
std::ranges::fold_left(r, non_movable(), std::plus());
160+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, non_movable, iterator_t<test_range<cpp20_input_iterator, copyable_non_movable> &> >' evaluated to false}}
161+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, non_movable, cpp20_input_iterator<copyable_non_movable *>, invoke_result_t<plus<void> &, non_movable, iter_reference_t<cpp20_input_iterator<copyable_non_movable *> > > >' evaluated to false}}
162+
// expected-note@*:* {{because 'non_movable' does not satisfy 'movable'}}
163+
// expected-note@*:* {{because 'non_movable' does not satisfy 'move_constructible'}}
164+
// expected-note@*:* {{because 'constructible_from<non_movable, non_movable>' evaluated to false}}
165+
// expected-note@*:* {{because 'is_constructible_v<non_movable, non_movable>' evaluated to false}}
166+
}
167+
{
168+
test_range<cpp20_input_iterator, copyable_non_movable> r;
169+
170+
std::ranges::fold_left(r, 0, std::minus());
171+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::minus<void>, int, iterator_t<test_range<cpp20_input_iterator, copyable_non_movable> &> >' evaluated to false}}
172+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::minus<void>, int, cpp20_input_iterator<copyable_non_movable *>, invoke_result_t<minus<void> &, int, iter_reference_t<cpp20_input_iterator<copyable_non_movable *> > > >' evaluated to false}}
173+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'movable'}}
174+
// expected-note@*:* {{because 'copyable_non_movable' does not satisfy 'move_constructible'}}
175+
// expected-note@*:* {{because 'constructible_from<copyable_non_movable, copyable_non_movable>' evaluated to false}}
176+
// expected-note@*:* {{because 'is_constructible_v<copyable_non_movable, copyable_non_movable>' evaluated to false}}
177+
}
178+
{
179+
test_range<cpp20_input_iterator, int> r;
180+
std::ranges::fold_left(r, not_convertible_to_int(), std::plus());
181+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_convertible_to_int, iterator_t<test_range<cpp20_input_iterator, int> &> >' evaluated to false}}
182+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_convertible_to_int, cpp20_input_iterator<int *>, invoke_result_t<plus<void> &, not_convertible_to_int, iter_reference_t<cpp20_input_iterator<int *> > > >' evaluated to false}}
183+
// expected-note@*:* {{because 'convertible_to<not_convertible_to_int, int>' evaluated to false}}
184+
// expected-note@*:* {{because 'is_convertible_v<not_convertible_to_int, int>' evaluated to false}}
185+
}
186+
{
187+
test_range<cpp20_input_iterator, not_invocable_with_decayed> r;
188+
std::ranges::fold_left(r, 0, std::plus());
189+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, int, iterator_t<test_range<cpp20_input_iterator, not_invocable_with_decayed> &> >' evaluated to false}}
190+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, int, cpp20_input_iterator<not_invocable_with_decayed *>, invoke_result_t<plus<void> &, int, iter_reference_t<cpp20_input_iterator<not_invocable_with_decayed *> > > >' evaluated to false}}
191+
// expected-note@*:* {{because 'invocable<std::plus<void> &, not_invocable_with_decayed, iter_reference_t<cpp20_input_iterator<not_invocable_with_decayed *> > >' evaluated to false}}
192+
// expected-note@*:* {{because 'std::invoke(std::forward<_Fn>(__fn), std::forward<_Args>(__args)...)' would be invalid: no matching function for call to 'invoke'}}
193+
}
194+
{
195+
test_range<cpp20_input_iterator, not_assignable_to_decayed> r;
196+
std::ranges::fold_left(r, not_assignable_to_decayed(), std::plus());
197+
// expected-note@*:* {{because '__indirectly_binary_left_foldable<std::plus<void>, not_assignable_to_decayed, iterator_t<test_range<cpp20_input_iterator, not_assignable_to_decayed> &> >' evaluated to false}}
198+
// expected-note@*:* {{because '__indirectly_binary_left_foldable_impl<std::plus<void>, not_assignable_to_decayed, cpp20_input_iterator<not_assignable_to_decayed *>, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<cpp20_input_iterator<not_assignable_to_decayed *> > > >' evaluated to false}}
199+
// expected-note@*:* {{because 'assignable_from<not_assignable_to_decayed &, invoke_result_t<plus<void> &, not_assignable_to_decayed, iter_reference_t<cpp20_input_iterator<not_assignable_to_decayed *> > > >' evaluated to false}}
200+
// expected-note@*:* {{because '__lhs = std::forward<_Rhs>(__rhs)' would be invalid: no viable overloaded '='}}
201+
}
202+
}

0 commit comments

Comments
 (0)