| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
|
| 3 |
// Copyright (C) 2019-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 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) |
| 9 |
// any later version. |
| 10 |
|
| 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. |
| 15 |
|
| 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/>. |
| 19 |
|
| 20 |
// C++17 29.8.3 [reduce] |
| 21 |
|
| 22 |
#include <numeric> |
| 23 |
#include <iterator> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
#include <testsuite_iterators.h> |
| 26 |
|
| 27 |
struct T |
| 28 |
{ |
| 29 |
T(int); |
| 30 |
T(T&&); // MoveConstructible |
| 31 |
T& operator=(T&&); // not required by the standard, but it needs to be |
| 32 |
T operator+(const T&) const; |
| 33 |
}; |
| 34 |
|
| 35 |
void |
| 36 |
test01() |
| 37 |
{ |
| 38 |
T t[1]{1}; |
| 39 |
std::reduce(t, t+1, T(0)); |
| 40 |
|
| 41 |
using __gnu_test::test_container; |
| 42 |
using __gnu_test::input_iterator_wrapper; |
| 43 |
test_container<T, input_iterator_wrapper> con(t); |
| 44 |
std::reduce(con.begin(), con.end(), T(0)); |
| 45 |
} |
| 46 |
|
| 47 |
struct Op |
| 48 |
{ |
| 49 |
T operator()(T&, T&) const&; |
| 50 |
|
| 51 |
// The standard does *not* require invoking as an rvalue to be supported. |
| 52 |
T operator()(T&, T&) && = delete; |
| 53 |
|
| 54 |
// The standard does *not* require rvalue arguments to be supported |
| 55 |
// (this is almost certainly a defect and should be allowed). |
| 56 |
T operator()(T&&, T&&) const = delete; |
| 57 |
}; |
| 58 |
|
| 59 |
void |
| 60 |
test02() |
| 61 |
{ |
| 62 |
T t[1]{1}; |
| 63 |
std::reduce(t, t+1, T(0), Op()); |
| 64 |
|
| 65 |
using __gnu_test::test_container; |
| 66 |
using __gnu_test::input_iterator_wrapper; |
| 67 |
test_container<T, input_iterator_wrapper> con(t); |
| 68 |
std::reduce(con.begin(), con.end(), T(0), Op()); |
| 69 |
} |