[LLD][COFF] Emit locally imported EC symbols for ARM64X (#125527)
[llvm-project.git] / libcxx / test / std / numerics / numeric.ops / reduce / reduce.pass.cpp
blob53a595e0bed3022493538e009af9d86aae81b085
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <numeric>
13 // Became constexpr in C++20
14 // template<class InputIterator>
15 // typename iterator_traits<InputIterator>::value_type
16 // reduce(InputIterator first, InputIterator last);
18 #include <numeric>
19 #include <cassert>
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);
33 template <class Iter>
34 TEST_CONSTEXPR_CXX20 void
35 test()
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);
45 template <typename T>
46 TEST_CONSTEXPR_CXX20 void
47 test_return_type()
49 T *p = nullptr;
50 static_assert( std::is_same_v<T, decltype(std::reduce(p, p))> );
53 TEST_CONSTEXPR_CXX20 bool
54 test()
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*> >();
66 test<const int*>();
68 return true;
71 int main(int, char**)
73 test();
74 #if TEST_STD_VER > 17
75 static_assert(test());
76 #endif
77 return 0;