]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/reduce/1.cc
78331043957e125b3d086ca658632c3dbe4b8879
1 // { dg-do run { target c++17 } }
3 // Copyright (C) 2019-2024 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // C++17 29.8.3 [reduce]
24 #include <testsuite_hooks.h>
25 #include <testsuite_iterators.h>
28 template<class InputIterator>
29 iterator_traits<InputIterator>::value_type
30 reduce(InputIterator, InputIterator);
35 using __gnu_test::test_container
;
36 using __gnu_test::input_iterator_wrapper
;
37 int array
[5] = { 1, 2, 3, 4, 5 };
38 test_container
<int, input_iterator_wrapper
> con(array
);
39 int res
= std::reduce(con
.begin(), con
.end());
44 template<class InputIterator, class T>
45 T reduce(InputIterator, InputIterator, T);
50 bool b
[] = {true, false, true, true, false, true, false, true, true, false};
51 int res
= std::reduce(std::begin(b
), std::end(b
), 100);
56 template<class InputIterator, class T>
57 T reduce(InputIterator, InputIterator, T);
58 template<class InputIterator, class T, class BinaryOperation>
59 T reduce(InputIterator, InputIterator, T, BinaryOperation);
64 int a
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
66 auto res
= std::reduce(std::begin(a
), std::end(a
), (short)11);
67 static_assert(std::is_same_v
<decltype(res
), short>);
70 auto res2
= std::reduce(std::begin(a
), std::end(a
), -1l, std::multiplies
<>());
71 static_assert(std::is_same_v
<decltype(res2
), long>);
72 VERIFY( res2
== -3628800 );