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