This adds constexpr to 11 algorithms defined in <numeric> as per P1645R1.
libstdc++-v3/ChangeLog:
P1645R1 constexpr for <numeric> algorithms
* include/bits/stl_numeric.h (iota, accumulate, inner_product,
partial_sum, adjacent_difference): Make conditionally constexpr for
C++20.
* include/std/numeric (__cpp_lib_constexpr_numeric): Define this feature
test macro.
(reduce, transform_reduce, exclusive_scan, inclusive_scan,
transform_exclusive_scan, transform_inclusive_scan): Make conditionally
constexpr for C++20.
* include/std/version (__cpp_lib_constexpr_numeric): Define.
* testsuite/26_numerics/accumulate/constexpr.cc: New test.
* testsuite/26_numerics/adjacent_difference/constexpr.cc: Likewise.
* testsuite/26_numerics/exclusive_scan/constexpr.cc: Likewise.
* testsuite/26_numerics/inclusive_scan/constexpr.cc: Likewise.
* testsuite/26_numerics/inner_product/constexpr.cc: Likewise.
* testsuite/26_numerics/iota/constexpr.cc: Likewise.
* testsuite/26_numerics/partial_sum/constexpr.cc: Likewise.
* testsuite/26_numerics/reduce/constexpr.cc: Likewise.
* testsuite/26_numerics/transform_exclusive_scan/constexpr.cc: Likewise.
* testsuite/26_numerics/transform_inclusive_scan/constexpr.cc: Likewise.
* testsuite/26_numerics/transform_reduce/constexpr.cc: Likewise.
+2020-02-26 Patrick Palka <ppalka@redhat.com>
+
+ P1645R1 constexpr for <numeric> algorithms
+ * include/bits/stl_numeric.h (iota, accumulate, inner_product,
+ partial_sum, adjacent_difference): Make conditionally constexpr for
+ C++20.
+ * include/std/numeric (__cpp_lib_constexpr_numeric): Define this feature
+ test macro.
+ (reduce, transform_reduce, exclusive_scan, inclusive_scan,
+ transform_exclusive_scan, transform_inclusive_scan): Make conditionally
+ constexpr for C++20.
+ * include/std/version (__cpp_lib_constexpr_numeric): Define.
+ * testsuite/26_numerics/accumulate/constexpr.cc: New test.
+ * testsuite/26_numerics/adjacent_difference/constexpr.cc: Likewise.
+ * testsuite/26_numerics/exclusive_scan/constexpr.cc: Likewise.
+ * testsuite/26_numerics/inclusive_scan/constexpr.cc: Likewise.
+ * testsuite/26_numerics/inner_product/constexpr.cc: Likewise.
+ * testsuite/26_numerics/iota/constexpr.cc: Likewise.
+ * testsuite/26_numerics/partial_sum/constexpr.cc: Likewise.
+ * testsuite/26_numerics/reduce/constexpr.cc: Likewise.
+ * testsuite/26_numerics/transform_exclusive_scan/constexpr.cc: Likewise.
+ * testsuite/26_numerics/transform_inclusive_scan/constexpr.cc: Likewise.
+ * testsuite/26_numerics/transform_reduce/constexpr.cc: Likewise.
+
2020-02-26 Jonathan Wakely <jwakely@redhat.com>
* include/bits/ranges_algo.h (__lexicographical_compare_fn): Declare
* @ingroup numeric_ops
*/
template<typename _ForwardIterator, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
{
* @return The final sum.
*/
template<typename _InputIterator, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
inline _Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
* @return The final sum.
*/
template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
+ _GLIBCXX20_CONSTEXPR
inline _Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
_BinaryOperation __binary_op)
* @return The final inner product.
*/
template<typename _InputIterator1, typename _InputIterator2, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
inline _Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init)
*/
template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
typename _BinaryOperation1, typename _BinaryOperation2>
+ _GLIBCXX20_CONSTEXPR
inline _Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init,
* @return Iterator pointing just beyond the values written to __result.
*/
template<typename _InputIterator, typename _OutputIterator>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
*/
template<typename _InputIterator, typename _OutputIterator,
typename _BinaryOperation>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
* DR 539. partial_sum and adjacent_difference should mention requirements
*/
template<typename _InputIterator, typename _OutputIterator>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
adjacent_difference(_InputIterator __first,
_InputIterator __last, _OutputIterator __result)
*/
template<typename _InputIterator, typename _OutputIterator,
typename _BinaryOperation>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#if __cplusplus > 201703L
+#define __cpp_lib_constexpr_numeric 201911L
+#endif
+
/// @addtogroup numeric_ops
/// @{
* arithmetic) the result can be different.
*/
template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
+ _GLIBCXX20_CONSTEXPR
_Tp
reduce(_InputIterator __first, _InputIterator __last, _Tp __init,
_BinaryOperation __binary_op)
* Equivalent to calling `std::reduce(first, last, init, std::plus<>())`.
*/
template<typename _InputIterator, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
inline _Tp
reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
{ return std::reduce(__first, __last, std::move(__init), plus<>()); }
* Equivalent to calling `std::reduce(first, last, T{}, std::plus<>())`.
*/
template<typename _InputIterator>
+ _GLIBCXX20_CONSTEXPR
inline typename iterator_traits<_InputIterator>::value_type
reduce(_InputIterator __first, _InputIterator __last)
{
*/
template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
typename _BinaryOperation1, typename _BinaryOperation2>
+ _GLIBCXX20_CONSTEXPR
_Tp
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init,
* elements.
*/
template<typename _InputIterator1, typename _InputIterator2, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
inline _Tp
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init)
*/
template<typename _InputIterator, typename _Tp,
typename _BinaryOperation, typename _UnaryOperation>
+ _GLIBCXX20_CONSTEXPR
_Tp
transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init,
_BinaryOperation __binary_op, _UnaryOperation __unary_op)
*/
template<typename _InputIterator, typename _OutputIterator, typename _Tp,
typename _BinaryOperation>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init,
* so the Nth input element is not included.
*/
template<typename _InputIterator, typename _OutputIterator, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
inline _OutputIterator
exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init)
*/
template<typename _InputIterator, typename _OutputIterator,
typename _BinaryOperation, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op,
*/
template<typename _InputIterator, typename _OutputIterator,
typename _BinaryOperation>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op)
* so the Nth input element is included.
*/
template<typename _InputIterator, typename _OutputIterator>
+ _GLIBCXX20_CONSTEXPR
inline _OutputIterator
inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
*/
template<typename _InputIterator, typename _OutputIterator, typename _Tp,
typename _BinaryOperation, typename _UnaryOperation>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init,
*/
template<typename _InputIterator, typename _OutputIterator,
typename _BinaryOperation, typename _UnaryOperation, typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result,
*/
template<typename _InputIterator, typename _OutputIterator,
typename _BinaryOperation, typename _UnaryOperation>
+ _GLIBCXX20_CONSTEXPR
_OutputIterator
transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result,
#define __cpp_lib_constexpr_complex 201711L
#define __cpp_lib_constexpr_dynamic_alloc 201907L
#define __cpp_lib_constexpr_invoke 201907L
+#define __cpp_lib_constexpr_numeric 201911L
#define __cpp_lib_erase_if 202002L
#define __cpp_lib_interpolate 201902L
#ifdef _GLIBCXX_HAS_GTHREADS
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[5] = {1,2,3,4,5};
+ auto sum = std::accumulate(x, x+5, 0);
+ return sum == 15;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[5] = {1,2,3,4,5};
+ auto prod = std::accumulate(x, x+5, 1, std::multiplies{});
+ return prod == 120;
+}
+
+static_assert(test02());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[5] = {1,2,3,4,5};
+ int y[5];
+ std::adjacent_difference(x, x+5, y);
+ return y[0] == 1 && y[1] == 1 && y[2] == 1 && y[3] == 1 && y[4] == 1;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[5] = {1,2,3,4,5};
+ int y[5];
+ std::adjacent_difference(x, x+5, y, std::multiplies{});
+ return y[0] == 1 && y[1] == 2 && y[2] == 6 && y[3] == 12 && y[4] == 20;
+}
+
+static_assert(test02());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::exclusive_scan(x, x+3, y, 0);
+ return y[0] == 0 && y[1] == 1 && y[2] == 3;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::exclusive_scan(x, x+3, y, 1, std::multiplies{});
+ return y[0] == 1 && y[1] == 1 && y[2] == 2;
+}
+
+static_assert(test02());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::inclusive_scan(x, x+3, y);
+ return y[0] == 1 && y[1] == 3 && y[2] == 6;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::inclusive_scan(x, x+3, y, std::multiplies{});
+ return y[0] == 1 && y[1] == 2 && y[2] == 6;
+}
+
+static_assert(test02());
+
+constexpr bool
+test03()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::inclusive_scan(x, x+3, y, std::multiplies{}, 2);
+ return y[0] == 2 && y[1] == 4 && y[2] == 12;
+}
+
+static_assert(test03());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[5] = {1,2,3,4,5};
+ int y[5] = {2,4,6,8,10};
+ auto ret = std::inner_product(x, x+5, y, 0);
+ return ret == 110;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[5] = {1,2,3,4,5};
+ int y[5] = {2,4,6,8,10};
+ auto ret = std::inner_product(x, x+5, y, 1,
+ std::multiplies{}, std::plus{});
+ return ret == 3*6*9*12*15;
+}
+
+static_assert(test02());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[3] = {0};
+ std::iota(x, x+3, 0);
+ return x[0] == 0 && x[1] == 1 && x[2] == 2;
+}
+
+static_assert(test01());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::partial_sum(x, x+3, y);
+ return y[0] == 1 && y[1] == 3 && y[2] == 6;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::partial_sum(x, x+3, y, std::multiplies{});
+ return y[0] == 1 && y[1] == 2 && y[2] == 6;
+}
+
+static_assert(test02());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[5] = {1,2,3,4,5};
+ auto sum = std::reduce(x, x+5);
+ return sum == 15;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[5] = {1,2,3,4,5};
+ auto sum = std::reduce(x, x+5, 0);
+ return sum == 15;
+}
+
+static_assert(test02());
+
+constexpr bool
+test03()
+{
+ int x[5] = {1,2,3,4,5};
+ auto prod = std::reduce(x, x+5, 1, std::multiplies{});
+ return prod == 120;
+}
+
+static_assert(test03());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::transform_exclusive_scan(x, x+3, y, 0, std::plus{}, std::negate{});
+ return y[0] == 0 && y[1] == -1 && y[2] == -3;
+}
+
+static_assert(test01());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::transform_inclusive_scan(x, x+3, y, std::plus{}, std::negate{}, 0);
+ return y[0] == -1 && y[1] == -3 && y[2] == -6;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[3] = {1,2,3};
+ int y[3];
+ std::transform_inclusive_scan(x, x+3, y, std::plus{}, std::negate{});
+ return y[0] == -1 && y[1] == -3 && y[2] == -6;
+}
+
+static_assert(test02());
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+#include <numeric>
+
+constexpr bool
+test01()
+{
+ int x[5] = {1,2,3,4,5};
+ int y[5] = {2,4,6,8,10};
+ auto ret = std::transform_reduce(x, x+5, y, 0);
+ return ret == 110;
+}
+
+static_assert(test01());
+
+constexpr bool
+test02()
+{
+ int x[5] = {1,2,3,4,5};
+ int y[5] = {2,4,6,8,10};
+ auto ret = std::transform_reduce(x, x+5, y, 1,
+ std::multiplies{}, std::plus{});
+ return ret == 3*6*9*12*15;
+}
+
+static_assert(test02());
+
+constexpr bool
+test03()
+{
+ int x[5] = {1,2,3,4,5};
+ auto ret = std::transform_reduce(x, x+5, 0, std::plus{}, std::negate{});
+ return ret == -15;
+}
+
+static_assert(test03());