On Fri, 28 Feb 2020, Jonathan Wakely wrote: > On 26/02/20 10:28 -0500, Patrick Palka wrote: > > On Wed, 26 Feb 2020, Jonathan Wakely wrote: > > > > > On 25/02/20 15:36 -0500, Patrick Palka wrote: > > > > This adds constexpr to 11 algorithms defined in <numeric> as per > > > P1645R1. > > > > > > > > Tested on x86_64-pc-linux-gnu, OK to commit? > > > > > > > > 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 (reduce, transform_reduce, exclusive_scan, > > > > inclusive_scan, transform_exclusive_scan, > > > > transform_inclusive_scan): > > > > Likewise. Define the feature test macro > > > > __cpp_lib_constexpr_numeric. > > > > * 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. > > testsuite/26_numerics/headers/numeric/synopsis.cc is now failing when > run with -std=gnu++2a. > > For testsuite/25_algorithms/headers/algorithm/synopsis.cc we just > added _GLIBCXX20_CONSTEXPR to the test as needed.
Does this look OK to commit? -- >8 -- Subject: [PATCH] libstdc++: Update the <numeric> synopsis test to latest standard Tested with make check RUNTESTFLAGS="conformance.exp=*numeric*synopsis* --target_board=unix/-std=$std" for std in {c++98, c++11, c++17, c++2a}. libstdc++-v3/ChangeLog: * testsuite/26_numerics/headers/numeric/synopsis.cc: Add signatures for functions introduced in C++11, C++17 and C++2a. Add 'constexpr' to existing signatures for C++2a. --- .../26_numerics/headers/numeric/synopsis.cc | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc b/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc index 8d3850ff0cf..5a9465c45f4 100644 --- a/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc +++ b/libstdc++-v3/testsuite/26_numerics/headers/numeric/synopsis.cc @@ -19,46 +19,157 @@ #include <numeric> +#if __cplusplus > 201703L +#define CONSTEXPR constexpr +#else +#define CONSTEXPR +#endif + namespace std { template <class InputIterator, class T> + CONSTEXPR T accumulate(InputIterator first, InputIterator last, T init); template <class InputIterator, class T, class BinaryOperation> + CONSTEXPR T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); template <class InputIterator1, class InputIterator2, class T> + CONSTEXPR T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2> + CONSTEXPR T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); template <class InputIterator, class OutputIterator> + CONSTEXPR OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result); template <class InputIterator, class OutputIterator, class BinaryOperation> + CONSTEXPR OutputIterator partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template <class InputIterator, class OutputIterator> + CONSTEXPR OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); template <class InputIterator, class OutputIterator, class BinaryOperation> + CONSTEXPR OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); +#if __cplusplus >= 201103L + template<class ForwardIterator, class T> + CONSTEXPR void iota(ForwardIterator first, ForwardIterator last, T value); +#endif // C++11 + +#if __cplusplus >= 201703L + template<class InputIterator> + CONSTEXPR typename iterator_traits<InputIterator>::value_type + reduce(InputIterator first, InputIterator last); + + template<class InputIterator, class T> + CONSTEXPR T reduce(InputIterator first, InputIterator last, T init); + + template<class InputIterator, class T, class BinaryOperation> + CONSTEXPR T reduce(InputIterator first, InputIterator last, T init, + BinaryOperation binary_op); + + template<class InputIterator, class OutputIterator, class T> + CONSTEXPR OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init); + + template<class InputIterator, class OutputIterator, class T, + class BinaryOperation> + CONSTEXPR OutputIterator + exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, BinaryOperation binary_op); + + template<class InputIterator, class OutputIterator> + CONSTEXPR OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result); + + template<class InputIterator, class OutputIterator, class BinaryOperation> + CONSTEXPR OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op); + + template<class InputIterator, class OutputIterator, class BinaryOperation, + class T> + CONSTEXPR OutputIterator + inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op, T init); + + template<class InputIterator1, class InputIterator2, class T> + CONSTEXPR T transform_reduce(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init); + + template<class InputIterator1, class InputIterator2, class T, + class BinaryOperation1, class BinaryOperation2> + CONSTEXPR T transform_reduce(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init, + BinaryOperation1 binary_op1, + BinaryOperation2 binary_op2); + + template<class InputIterator, class T, + class BinaryOperation, class UnaryOperation> + CONSTEXPR T transform_reduce(InputIterator first, InputIterator last, T init, + BinaryOperation binary_op, + UnaryOperation unary_op); + + template<class InputIterator, class OutputIterator, class T, + class BinaryOperation, class UnaryOperation> + CONSTEXPR OutputIterator + transform_exclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, T init, + BinaryOperation binary_op, UnaryOperation unary_op); + + template<class InputIterator, class OutputIterator, + class BinaryOperation, class UnaryOperation> + CONSTEXPR OutputIterator + transform_inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, + BinaryOperation binary_op, UnaryOperation unary_op); + + template<class InputIterator, class OutputIterator, + class BinaryOperation, class UnaryOperation, class T> + CONSTEXPR OutputIterator + transform_inclusive_scan(InputIterator first, InputIterator last, + OutputIterator result, + BinaryOperation binary_op, UnaryOperation unary_op, + T init); +#endif // C++17 + +#if __cplusplus > 201703L + template<class M, class N> + constexpr common_type_t<M,N> gcd(M m, N n); + + template<class M, class N> + constexpr common_type_t<M,N> lcm(M m, N n); + + template<class T> + constexpr T midpoint(T a, T b) noexcept; + + template<class T> + constexpr T* midpoint(T* a, T* b); +#endif // C++2a } -- 2.25.1.377.g2d2118b814