d: Merge dmd, druntime c7902293d7, phobos 03aeafd20
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / fold_right / 1.cc
blob207d51f5a73a0e0991261dff0d2001d783c2f0dc
1 // { dg-do run { target c++23 } }
3 #include <algorithm>
4 #include <ranges>
5 #include <testsuite_iterators.h>
7 namespace ranges = std::ranges;
8 namespace views = std::views;
10 constexpr bool
11 test01()
13 int x[] = {1, 2, 3, 4, 5};
14 auto v = x | views::filter([](int) { return true; });
15 static_assert( ranges::bidirectional_range<decltype(v)>
16 && !ranges::random_access_range<decltype(v)> );
17 auto f = [](int& x, int&& acc) {
18 return 2 * acc + x;
20 VERIFY( ranges::fold_right(v, 0, f) == 129 );
21 VERIFY( ranges::fold_right(v, 1, f) == 161 );
22 VERIFY( ranges::fold_right(v.begin(), v.begin(), 1, f) == 1 );
24 VERIFY( ranges::fold_right_last(v, f).value() == 129 );
25 VERIFY( !ranges::fold_right_last(v.begin(), v.begin(), f).has_value() );
27 return true;
30 constexpr bool
31 test02()
33 double x[] = {0.5, 0.25, 0.125, 0.125};
34 VERIFY( ranges::fold_right(x, 0, std::plus{}) == 1.0 );
36 return true;
39 int
40 main()
42 static_assert(test01());
43 static_assert(test02());