1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // Became constexpr in C++20
14 // template<class InputIterator>
15 // typename iterator_traits<InputIterator>::value_type
16 // reduce(InputIterator first, InputIterator last);
21 #include "test_macros.h"
22 #include "test_iterators.h"
24 template <class Iter
, class T
>
25 TEST_CONSTEXPR_CXX20
void
26 test(Iter first
, Iter last
, T x
)
28 static_assert( std::is_same_v
<typename
std::iterator_traits
<decltype(first
)>::value_type
,
29 decltype(std::reduce(first
, last
))> );
30 assert(std::reduce(first
, last
) == x
);
34 TEST_CONSTEXPR_CXX20
void
37 int ia
[] = {1, 2, 3, 4, 5, 6};
38 unsigned sa
= sizeof(ia
) / sizeof(ia
[0]);
39 test(Iter(ia
), Iter(ia
), 0);
40 test(Iter(ia
), Iter(ia
+1), 1);
41 test(Iter(ia
), Iter(ia
+2), 3);
42 test(Iter(ia
), Iter(ia
+sa
), 21);
46 TEST_CONSTEXPR_CXX20
void
50 static_assert( std::is_same_v
<T
, decltype(std::reduce(p
, p
))> );
53 TEST_CONSTEXPR_CXX20
bool
56 test_return_type
<char>();
57 test_return_type
<int>();
58 test_return_type
<unsigned long>();
59 test_return_type
<float>();
60 test_return_type
<double>();
62 test
<cpp17_input_iterator
<const int*> >();
63 test
<forward_iterator
<const int*> >();
64 test
<bidirectional_iterator
<const int*> >();
65 test
<random_access_iterator
<const int*> >();
75 static_assert(test());