diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst --- a/libcxx/docs/FeatureTestMacroTable.rst +++ b/libcxx/docs/FeatureTestMacroTable.rst @@ -196,6 +196,8 @@ ------------------------------------------------- ----------------- ``__cpp_lib_constexpr_misc`` *unimplemented* ------------------------------------------------- ----------------- + ``__cpp_lib_constexpr_numeric`` ``201911L`` + ------------------------------------------------- ----------------- ``__cpp_lib_constexpr_swap_algorithms`` *unimplemented* ------------------------------------------------- ----------------- ``__cpp_lib_constexpr_utility`` ``201811L`` diff --git a/libcxx/include/numeric b/libcxx/include/numeric --- a/libcxx/include/numeric +++ b/libcxx/include/numeric @@ -17,115 +17,116 @@ { template - T + constexpr T // constexpr since C++20 accumulate(InputIterator first, InputIterator last, T init); template - T + constexpr T // constexpr since C++20 accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); template - typename iterator_traits::value_type + constexpr typename iterator_traits::value_type // constexpr since C++20 reduce(InputIterator first, InputIterator last); // C++17 template - T + constexpr T // constexpr since C++20 reduce(InputIterator first, InputIterator last, T init); // C++17 template - T + constexpr T // constexpr since C++20 reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17 template - T + constexpr T // constexpr since C++20 inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); template - T + constexpr T // constexpr since C++20 inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); template - T + constexpr T // constexpr since C++20 transform_reduce(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init); // C++17 template - T + constexpr T // constexpr since C++20 transform_reduce(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17 template - T + constexpr T // constexpr since C++20 transform_reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op, UnaryOperation unary_op); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 partial_sum(InputIterator first, InputIterator last, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr since C++20 partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template - OutputIterator + constexpr OutputIterator // constexpr since C++20 exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 transform_exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op, UnaryOperation unary_op); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 transform_inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, UnaryOperation unary_op); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 transform_inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, UnaryOperation unary_op, T init); // C++17 template - OutputIterator + constexpr OutputIterator // constexpr since C++20 adjacent_difference(InputIterator first, InputIterator last, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr since C++20 adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op); template - void iota(ForwardIterator first, ForwardIterator last, T value); + constexpr void // constexpr since C++20 + iota(ForwardIterator first, ForwardIterator last, T value); template constexpr common_type_t gcd(M m, N n); // C++17 @@ -133,9 +134,11 @@ template constexpr common_type_t lcm(M m, N n); // C++17 -integer midpoint(integer a, integer b); // C++20 -pointer midpoint(pointer a, pointer b); // C++20 -floating_point midpoint(floating_point a, floating_point b); // C++20 +template + constexpr T midpoint(T a, T b) noexcept; // C++20 + +template + constexpr T* midpoint(T* a, T* b); // C++20 } // std @@ -158,7 +161,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) { @@ -168,7 +171,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) { @@ -179,7 +182,7 @@ #if _LIBCPP_STD_VER > 14 template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b) { @@ -189,7 +192,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last, _Tp __init) { @@ -197,7 +200,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::value_type reduce(_InputIterator __first, _InputIterator __last) { @@ -207,7 +210,7 @@ #endif template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) { @@ -217,7 +220,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2) @@ -229,7 +232,7 @@ #if _LIBCPP_STD_VER > 14 template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b, _UnaryOp __u) @@ -241,7 +244,7 @@ template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2) @@ -252,7 +255,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) @@ -263,7 +266,7 @@ #endif template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { @@ -281,7 +284,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) @@ -301,7 +304,7 @@ #if _LIBCPP_STD_VER > 14 template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) @@ -321,7 +324,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) @@ -330,6 +333,7 @@ } template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) { @@ -341,6 +345,7 @@ } template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) { @@ -355,6 +360,7 @@ } template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { @@ -363,7 +369,7 @@ template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator transform_exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, @@ -384,7 +390,9 @@ } template -_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform_inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init) { for (; __first != __last; ++__first, (void) ++__result) { @@ -396,7 +404,9 @@ } template -_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last, +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform_inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _UnaryOp __u) { if (__first != __last) { @@ -411,7 +421,7 @@ #endif template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { @@ -430,7 +440,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) @@ -450,7 +460,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) { diff --git a/libcxx/include/version b/libcxx/include/version --- a/libcxx/include/version +++ b/libcxx/include/version @@ -48,6 +48,7 @@ __cpp_lib_constexpr_dynamic_alloc 201907L __cpp_lib_constexpr_misc 201811L +__cpp_lib_constexpr_numeric 201911L __cpp_lib_constexpr_swap_algorithms 201806L __cpp_lib_constexpr_utility 201811L __cpp_lib_destroying_delete 201806L @@ -254,6 +255,7 @@ // # define __cpp_lib_concepts 201806L # define __cpp_lib_constexpr_dynamic_alloc 201907L // # define __cpp_lib_constexpr_misc 201811L +# define __cpp_lib_constexpr_numeric 201911L // # define __cpp_lib_constexpr_swap_algorithms 201806L # define __cpp_lib_constexpr_utility 201811L # if _LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.pass.cpp --- a/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/numeric.version.pass.cpp @@ -14,6 +14,7 @@ // Test the feature test macros defined by /* Constant Value + __cpp_lib_constexpr_numeric 201911L [C++2a] __cpp_lib_gcd_lcm 201606L [C++17] __cpp_lib_interpolate 201902L [C++2a] __cpp_lib_parallel_algorithm 201603L [C++17] @@ -24,6 +25,10 @@ #if TEST_STD_VER < 14 +# ifdef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should not be defined before c++2a" +# endif + # ifdef __cpp_lib_gcd_lcm # error "__cpp_lib_gcd_lcm should not be defined before c++17" # endif @@ -38,6 +43,10 @@ #elif TEST_STD_VER == 14 +# ifdef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should not be defined before c++2a" +# endif + # ifdef __cpp_lib_gcd_lcm # error "__cpp_lib_gcd_lcm should not be defined before c++17" # endif @@ -52,6 +61,10 @@ #elif TEST_STD_VER == 17 +# ifdef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should not be defined before c++2a" +# endif + # ifndef __cpp_lib_gcd_lcm # error "__cpp_lib_gcd_lcm should be defined in c++17" # endif @@ -78,6 +91,13 @@ #elif TEST_STD_VER > 17 +# ifndef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should be defined in c++2a" +# endif +# if __cpp_lib_constexpr_numeric != 201911L +# error "__cpp_lib_constexpr_numeric should have the value 201911L in c++2a" +# endif + # ifndef __cpp_lib_gcd_lcm # error "__cpp_lib_gcd_lcm should be defined in c++2a" # endif diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp --- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp +++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp @@ -42,6 +42,7 @@ __cpp_lib_concepts 201806L [C++2a] __cpp_lib_constexpr_dynamic_alloc 201907L [C++2a] __cpp_lib_constexpr_misc 201811L [C++2a] + __cpp_lib_constexpr_numeric 201911L [C++2a] __cpp_lib_constexpr_swap_algorithms 201806L [C++2a] __cpp_lib_constexpr_utility 201811L [C++2a] __cpp_lib_destroying_delete 201806L [C++2a] @@ -227,6 +228,10 @@ # error "__cpp_lib_constexpr_misc should not be defined before c++2a" # endif +# ifdef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should not be defined before c++2a" +# endif + # ifdef __cpp_lib_constexpr_swap_algorithms # error "__cpp_lib_constexpr_swap_algorithms should not be defined before c++2a" # endif @@ -619,6 +624,10 @@ # error "__cpp_lib_constexpr_misc should not be defined before c++2a" # endif +# ifdef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should not be defined before c++2a" +# endif + # ifdef __cpp_lib_constexpr_swap_algorithms # error "__cpp_lib_constexpr_swap_algorithms should not be defined before c++2a" # endif @@ -1125,6 +1134,10 @@ # error "__cpp_lib_constexpr_misc should not be defined before c++2a" # endif +# ifdef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should not be defined before c++2a" +# endif + # ifdef __cpp_lib_constexpr_swap_algorithms # error "__cpp_lib_constexpr_swap_algorithms should not be defined before c++2a" # endif @@ -1910,6 +1923,13 @@ # endif # endif +# ifndef __cpp_lib_constexpr_numeric +# error "__cpp_lib_constexpr_numeric should be defined in c++2a" +# endif +# if __cpp_lib_constexpr_numeric != 201911L +# error "__cpp_lib_constexpr_numeric should have the value 201911L in c++2a" +# endif + # if !defined(_LIBCPP_VERSION) # ifndef __cpp_lib_constexpr_swap_algorithms # error "__cpp_lib_constexpr_swap_algorithms should be defined in c++2a" diff --git a/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp b/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template // requires HasPlus // && HasAssign::result_type> @@ -21,14 +22,14 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter first, Iter last, T init, T x) { assert(std::accumulate(first, last, init) == x); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -43,7 +44,8 @@ test(Iter(ia), Iter(ia+sa), 10, 31); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test >(); test >(); @@ -51,5 +53,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/accumulate/accumulate_op.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template BinaryOperation> // requires HasAssign @@ -23,14 +24,14 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter first, Iter last, T init, T x) { assert(std::accumulate(first, last, init, std::multiplies()) == x); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -45,7 +46,8 @@ test(Iter(ia), Iter(ia+sa), 10, 7200); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test >(); test >(); @@ -53,5 +55,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp b/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template OutIter> // requires HasMinus @@ -25,7 +26,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {15, 10, 6, 3, 1}; @@ -46,18 +47,18 @@ { int i_; - X& operator=(const X&); + TEST_CONSTEXPR_CXX20 X& operator=(const X&); public: - explicit X(int i) : i_(i) {} - X(const X& x) : i_(x.i_) {} - X& operator=(X&& x) + TEST_CONSTEXPR_CXX20 explicit X(int i) : i_(i) {} + TEST_CONSTEXPR_CXX20 X(const X& x) : i_(x.i_) {} + TEST_CONSTEXPR_CXX20 X& operator=(X&& x) { i_ = x.i_; x.i_ = -1; return *this; } - friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} + TEST_CONSTEXPR_CXX20 friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} friend class Y; }; @@ -66,16 +67,17 @@ { int i_; - Y& operator=(const Y&); + TEST_CONSTEXPR_CXX20 Y& operator=(const Y&); public: - explicit Y(int i) : i_(i) {} - Y(const Y& y) : i_(y.i_) {} - void operator=(const X& x) {i_ = x.i_;} + TEST_CONSTEXPR_CXX20 explicit Y(int i) : i_(i) {} + TEST_CONSTEXPR_CXX20 Y(const Y& y) : i_(y.i_) {} + TEST_CONSTEXPR_CXX20 void operator=(const X& x) {i_ = x.i_;} }; #endif -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test, output_iterator >(); test, forward_iterator >(); @@ -113,5 +115,14 @@ std::adjacent_difference(x, x+3, y); #endif - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/adjacent.difference/adjacent_difference_op.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template OutIter, // Callable BinaryOperation> @@ -26,7 +27,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {15, 10, 6, 3, 1}; @@ -48,18 +49,18 @@ { int i_; - X& operator=(const X&); + TEST_CONSTEXPR_CXX20 X& operator=(const X&); public: - explicit X(int i) : i_(i) {} - X(const X& x) : i_(x.i_) {} - X& operator=(X&& x) + TEST_CONSTEXPR_CXX20 explicit X(int i) : i_(i) {} + TEST_CONSTEXPR_CXX20 X(const X& x) : i_(x.i_) {} + TEST_CONSTEXPR_CXX20 X& operator=(X&& x) { i_ = x.i_; x.i_ = -1; return *this; } - friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} + TEST_CONSTEXPR_CXX20 friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);} friend class Y; }; @@ -68,17 +69,18 @@ { int i_; - Y& operator=(const Y&); + TEST_CONSTEXPR_CXX20 Y& operator=(const Y&); public: - explicit Y(int i) : i_(i) {} - Y(const Y& y) : i_(y.i_) {} - void operator=(const X& x) {i_ = x.i_;} + TEST_CONSTEXPR_CXX20 explicit Y(int i) : i_(i) {} + TEST_CONSTEXPR_CXX20 Y(const Y& y) : i_(y.i_) {} + TEST_CONSTEXPR_CXX20 void operator=(const X& x) {i_ = x.i_;} }; #endif -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test, output_iterator >(); test, forward_iterator >(); @@ -116,5 +118,14 @@ std::adjacent_difference(x, x+3, y, std::minus()); #endif - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator exclusive_scan(InputIterator first, InputIterator last, // OutputIterator result, T init); @@ -16,6 +17,7 @@ #include #include +#include #include #include #include @@ -23,27 +25,42 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, T init, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif // Not in place - std::exclusive_scan(first, last, std::back_inserter(v), init); + std::exclusive_scan(first, last, v.begin(), init); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // In place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::exclusive_scan(v.begin(), v.end(), v.begin(), init); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } - template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 3, 5, 7, 9}; @@ -55,13 +72,14 @@ test(Iter(ia), Iter(ia + i), 0, pRes, pRes + i); } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::exclusive_scan(v.begin(), v.end(), v.begin(), size_t{50}); for (size_t i = 0; i < v.size(); ++i) @@ -69,7 +87,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::exclusive_scan(v.begin(), v.end(), v.begin(), size_t{30}); for (size_t i = 0; i < v.size(); ++i) @@ -77,7 +95,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::exclusive_scan(v.begin(), v.end(), v.begin(), size_t{40}); for (size_t i = 0; i < v.size(); ++i) @@ -86,7 +104,8 @@ } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { basic_tests(); @@ -98,5 +117,14 @@ test(); test< int*>(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator // exclusive_scan(InputIterator first, InputIterator last, @@ -17,6 +18,7 @@ #include #include +#include #include #include #include @@ -24,27 +26,43 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, T init, Op op, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif // Not in place - std::exclusive_scan(first, last, std::back_inserter(v), init, op); + std::exclusive_scan(first, last, v.begin(), init, op); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // In place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::exclusive_scan(v.begin(), v.end(), v.begin(), init, op); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 3, 5, 7, 9}; @@ -60,7 +78,8 @@ } } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { // All the iterator categories test >(); @@ -72,10 +91,20 @@ // Make sure that the calculations are done using the init typedef { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), static_cast(1)); + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector res; std::exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>()); +#else + std::array res; + std::exclusive_scan(v.begin(), v.end(), res.begin(), 1, std::multiplies<>()); +#endif assert(res.size() == 10); size_t j = 1; @@ -87,5 +116,14 @@ } } - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator inclusive_scan(InputIterator first, InputIterator last, // OutputIterator result, T init); @@ -16,6 +17,7 @@ #include #include +#include #include #include #include @@ -23,27 +25,43 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif // Not in place - std::inclusive_scan(first, last, std::back_inserter(v)); + std::inclusive_scan(first, last, v.begin()); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // In place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::inclusive_scan(v.begin(), v.end(), v.begin()); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 3, 5, 7, 9}; @@ -55,13 +73,14 @@ test(Iter(ia), Iter(ia + i), pRes, pRes + i); } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::inclusive_scan(v.begin(), v.end(), v.begin()); for (size_t i = 0; i < v.size(); ++i) @@ -69,7 +88,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::inclusive_scan(v.begin(), v.end(), v.begin()); for (size_t i = 0; i < v.size(); ++i) @@ -77,7 +96,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::inclusive_scan(v.begin(), v.end(), v.begin()); for (size_t i = 0; i < v.size(); ++i) @@ -85,13 +104,24 @@ } { + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector v, res; std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res)); +#else + std::array v, res; + std::inclusive_scan(v.begin(), v.end(), res.begin()); +#endif assert(res.empty()); } } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { basic_tests(); @@ -103,5 +133,14 @@ test(); test< int*>(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator // inclusive_scan(InputIterator first, InputIterator last, @@ -17,6 +18,7 @@ #include #include +#include #include #include #include @@ -24,27 +26,43 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif -template -void +template +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, Op op, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif // Not in place - std::inclusive_scan(first, last, std::back_inserter(v), op); + std::inclusive_scan(first, last, v.begin(), op); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // In place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::inclusive_scan(v.begin(), v.end(), v.begin(), op); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 3, 5, 7, 9}; @@ -60,13 +78,14 @@ } } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>()); for (size_t i = 0; i < v.size(); ++i) @@ -74,7 +93,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>()); for (size_t i = 0; i < v.size(); ++i) @@ -82,7 +101,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>()); for (size_t i = 0; i < v.size(); ++i) @@ -90,26 +109,43 @@ } { + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector v, res; std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>()); +#else + std::array v, res; + std::inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>()); +#endif assert(res.empty()); } } - -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { - basic_tests(); // All the iterator categories -// test >(); -// test >(); -// test >(); -// test >(); -// test(); -// test< int*>(); - + test >(); + test >(); + test >(); + test >(); + test(); + test< int*>(); + + return true; +} - return 0; +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator // inclusive_scan(InputIterator first, InputIterator last, @@ -17,6 +18,7 @@ #include #include +#include #include #include #include @@ -24,27 +26,43 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, Op op, T init, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif // Not in place - std::inclusive_scan(first, last, std::back_inserter(v), op, init); + std::inclusive_scan(first, last, v.begin(), op, init); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // In place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::inclusive_scan(v.begin(), v.end(), v.begin(), op, init); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 3, 5, 7, 9}; @@ -60,13 +78,14 @@ } } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), size_t{50}); for (size_t i = 0; i < v.size(); ++i) @@ -74,7 +93,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), size_t{40}); for (size_t i = 0; i < v.size(); ++i) @@ -82,7 +101,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), size_t{30}); for (size_t i = 0; i < v.size(); ++i) @@ -90,17 +109,37 @@ } { + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector v, res; std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), size_t{40}); +#else + std::array v, res; + std::inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), size_t{40}); +#endif assert(res.empty()); } // Make sure that the calculations are done using the init typedef { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), static_cast(1)); + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector res; std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), size_t{1}); +#else + std::array res; + std::inclusive_scan(v.begin(), v.end(), res.begin(), std::multiplies<>(), size_t{1}); +#endif assert(res.size() == 10); size_t j = 1; @@ -113,10 +152,9 @@ } } - -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { - basic_tests(); // All the iterator categories @@ -127,6 +165,14 @@ test(); test< int*>(); + return true; +} - return 0; +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template // requires HasMultiply // && HasPlus::result_type> @@ -25,14 +26,14 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) { assert(std::inner_product(first1, last1, first2, init) == x); } template -void +TEST_CONSTEXPR_CXX20 void test() { int a[] = {1, 2, 3, 4, 5, 6}; @@ -48,7 +49,8 @@ test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 66); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test, input_iterator >(); test, forward_iterator >(); @@ -80,5 +82,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/inner.product/inner_product_comp.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template BinaryOperation2> @@ -27,7 +28,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) { assert(std::inner_product(first1, last1, first2, init, @@ -35,7 +36,7 @@ } template -void +TEST_CONSTEXPR_CXX20 void test() { int a[] = {1, 2, 3, 4, 5, 6}; @@ -51,7 +52,8 @@ test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 1176490); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test, input_iterator >(); test, forward_iterator >(); @@ -83,5 +85,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp b/libcxx/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/numeric.iota/iota.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template // void iota(ForwardIterator first, ForwardIterator last, T value); @@ -18,7 +19,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5}; @@ -29,12 +30,22 @@ assert(ia[i] == ir[i]); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test >(); test >(); test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp b/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template OutIter> // requires HasPlus // && HasAssign -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5}; @@ -36,7 +37,8 @@ assert(ib[i] == ir[i]); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test, output_iterator >(); test, forward_iterator >(); @@ -68,5 +70,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/partial.sum/partial_sum_op.pass.cpp @@ -8,6 +8,7 @@ // +// Became constexpr in C++20 // template OutIter, // Callable BinaryOperation> @@ -25,7 +26,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5}; @@ -38,7 +39,8 @@ assert(ib[i] == ir[i]); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test, output_iterator >(); test, forward_iterator >(); @@ -70,5 +72,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/reduce/reduce.pass.cpp b/libcxx/test/std/numerics/numeric.ops/reduce/reduce.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/reduce/reduce.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/reduce/reduce.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // typename iterator_traits::value_type // reduce(InputIterator first, InputIterator last); @@ -20,7 +21,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter first, Iter last, T x) { static_assert( std::is_same_v::value_type, @@ -29,7 +30,7 @@ } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -41,13 +42,15 @@ } template -void test_return_type() +TEST_CONSTEXPR_CXX20 void +test_return_type() { T *p = nullptr; static_assert( std::is_same_v ); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test_return_type(); test_return_type(); @@ -61,5 +64,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init.pass.cpp b/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // T reduce(InputIterator first, InputIterator last, T init); @@ -19,7 +20,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter first, Iter last, T init, T x) { static_assert( std::is_same_v ); @@ -27,7 +28,7 @@ } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -43,13 +44,15 @@ } template -void test_return_type() +TEST_CONSTEXPR_CXX20 void +test_return_type() { T *p = nullptr; static_assert( std::is_same_v ); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test_return_type(); test_return_type(); @@ -65,5 +68,14 @@ test >(); test(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // T reduce(InputIterator first, InputIterator last, T init, BinaryOperation op); @@ -19,7 +20,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter first, Iter last, T init, Op op, T x) { static_assert( std::is_same_v, "" ); @@ -27,7 +28,7 @@ } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -43,13 +44,15 @@ } template -void test_return_type() +TEST_CONSTEXPR_CXX20 void +test_return_type() { T *p = nullptr; static_assert( std::is_same_v()))>, "" ); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test_return_type(); test_return_type(); @@ -72,5 +75,14 @@ assert(res == 40320); // 8! will not fit into a char } - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last, @@ -19,6 +20,7 @@ #include #include +#include #include #include #include @@ -26,6 +28,10 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif struct add_one { template @@ -35,24 +41,37 @@ }; template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif + // Test not in-place - std::transform_exclusive_scan(first, last, std::back_inserter(v), init, bop, uop); + std::transform_exclusive_scan(first, last, v.begin(), init, bop, uop); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // Test in-place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), init, bop, uop); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = { 1, 3, 5, 7, 9 }; @@ -86,13 +105,14 @@ } } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), size_t{50}, std::plus<>(), add_one{}); for (size_t i = 0; i < v.size(); ++i) @@ -100,7 +120,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), size_t{30}, std::plus<>(), add_one{}); for (size_t i = 0; i < v.size(); ++i) @@ -108,7 +128,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), size_t{40}, std::plus<>(), add_one{}); for (size_t i = 0; i < v.size(); ++i) @@ -116,17 +136,37 @@ } { + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector v, res; std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{40}, std::plus<>(), add_one{}); +#else + std::array v, res; + std::transform_exclusive_scan(v.begin(), v.end(), res.begin(), size_t{40}, std::plus<>(), add_one{}); +#endif assert(res.empty()); } // Make sure that the calculations are done using the init typedef { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), static_cast(1)); + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector res; std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{1}, std::multiplies<>(), add_one{}); +#else + std::array res; + std::transform_exclusive_scan(v.begin(), v.end(), res.begin(), size_t{1}, std::multiplies<>(), add_one{}); +#endif assert(res.size() == 10); size_t j = 1; @@ -139,7 +179,8 @@ } } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { basic_tests(); @@ -151,5 +192,14 @@ test(); test< int*>(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp @@ -10,6 +10,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, @@ -20,6 +21,7 @@ #include #include +#include #include #include #include @@ -27,6 +29,10 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif struct add_one { template @@ -36,24 +42,37 @@ }; template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, BOp bop, UOp uop, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif + // Test not in-place - std::transform_inclusive_scan(first, last, std::back_inserter(v), bop, uop); + std::transform_inclusive_scan(first, last, v.begin(), bop, uop); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // Test in-place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), bop, uop); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = { 1, 3, 5, 7, 9 }; @@ -75,13 +94,14 @@ } } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}); for (size_t i = 0; i < v.size(); ++i) @@ -89,7 +109,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}); for (size_t i = 0; i < v.size(); ++i) @@ -97,7 +117,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}); for (size_t i = 0; i < v.size(); ++i) @@ -105,13 +125,24 @@ } { + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector v, res; std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{}); +#else + std::array v, res; + std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), add_one{}); +#endif assert(res.empty()); } } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { basic_tests(); @@ -123,5 +154,14 @@ test(); test< int*>(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last, @@ -20,6 +21,7 @@ #include #include +#include #include #include #include @@ -27,6 +29,10 @@ #include "test_macros.h" #include "test_iterators.h" +// FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER > 17 +#include +#endif struct add_one { template @@ -36,24 +42,37 @@ }; template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast) { - std::vector::value_type> v; + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 + size_t size = std::distance(first, last); +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) + + std::vector::value_type> v(size); +#else + assert((size <= 5) && "Increment the size of the array"); + typename std::iterator_traits::value_type b[5]; + std::span::value_type> v{b, size}; +#endif + // Test not in-place - std::transform_inclusive_scan(first, last, std::back_inserter(v), bop, uop, init); + std::transform_inclusive_scan(first, last, v.begin(), bop, uop, init); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); // Test in-place - v.clear(); - v.assign(first, last); + std::copy(first, last, v.begin()); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), bop, uop, init); assert(std::equal(v.begin(), v.end(), rFirst, rLast)); } template -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = { 1, 3, 5, 7, 9 }; @@ -87,13 +106,14 @@ } } -size_t triangle(size_t n) { return n*(n+1)/2; } +constexpr size_t triangle(size_t n) { return n*(n+1)/2; } // Basic sanity -void basic_tests() +TEST_CONSTEXPR_CXX20 void +basic_tests() { { - std::vector v(10); + std::array v; std::fill(v.begin(), v.end(), 3); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}, size_t{50}); for (size_t i = 0; i < v.size(); ++i) @@ -101,7 +121,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 0); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}, size_t{30}); for (size_t i = 0; i < v.size(); ++i) @@ -109,7 +129,7 @@ } { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), 1); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}, size_t{40}); for (size_t i = 0; i < v.size(); ++i) @@ -117,17 +137,37 @@ } { + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector v, res; std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{}, size_t{1}); +#else + std::array v, res; + std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), add_one{}, size_t{1}); +#endif assert(res.empty()); } // Make sure that the calculations are done using the init typedef { - std::vector v(10); + std::array v; std::iota(v.begin(), v.end(), static_cast(1)); + // C++17 doesn't test constexpr so can use a vector. + // C++20 can use vector in constexpr evaluation, but both libc++ and MSVC + // don't have the support yet. In these cases use a std::span for the test. + // FIXME Remove constexpr vector workaround introduced in D90569 +#if TEST_STD_VER < 20 || \ + (defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L) std::vector res; std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), add_one{}, size_t{1}); +#else + std::array res; + std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::multiplies<>(), add_one{}, size_t{1}); +#endif assert(res.size() == 10); size_t j = 2; @@ -140,7 +180,8 @@ } } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { basic_tests(); @@ -152,5 +193,14 @@ test(); test< int*>(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // T transform_reduce(InputIterator1 first1, InputIterator1 last1, @@ -41,7 +42,7 @@ }; template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first1, Iter1 last1, T init, BOp bOp, UOp uOp, T x) { static_assert( std::is_same_v -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -76,14 +77,16 @@ } template -void test_return_type() +TEST_CONSTEXPR_CXX20 void +test_return_type() { T *p = nullptr; static_assert( std::is_same_v(), identity()))> ); } -void test_move_only_types() +TEST_CONSTEXPR_CXX20 void +test_move_only_types() { MoveOnly ia[] = {{1}, {2}, {3}}; assert(60 == @@ -92,7 +95,8 @@ [](const MoveOnly& target) { return MoveOnly{target.get() * 10}; }).get()); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test_return_type(); test_return_type(); @@ -119,5 +123,14 @@ test_move_only_types(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // T transform_reduce(InputIterator1 first1, InputIterator1 last1, // InputIterator2 first2, T init); @@ -23,7 +24,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x) { static_assert( std::is_same_v -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -51,14 +52,16 @@ } template -void test_return_type() +TEST_CONSTEXPR_CXX20 void +test_return_type() { T *p = nullptr; static_assert( std::is_same_v ); } -void test_move_only_types() +TEST_CONSTEXPR_CXX20 void +test_move_only_types() { MoveOnly ia[] = {{1}, {2}, {3}}; MoveOnly ib[] = {{1}, {2}, {3}}; @@ -66,7 +69,8 @@ std::transform_reduce(std::begin(ia), std::end(ia), std::begin(ib), MoveOnly{0}).get()); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test_return_type(); test_return_type(); @@ -105,5 +109,14 @@ test_move_only_types(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp --- a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp @@ -9,6 +9,7 @@ // // UNSUPPORTED: c++03, c++11, c++14 +// Became constexpr in C++20 // template // T transform_reduce(InputIterator1 first1, InputIterator1 last1, @@ -25,7 +26,7 @@ #include "test_iterators.h" template -void +TEST_CONSTEXPR_CXX20 void test(Iter1 first1, Iter1 last1, Iter2 first2, T init, Op1 op1, Op2 op2, T x) { static_assert( std::is_same_v -void +TEST_CONSTEXPR_CXX20 void test() { int ia[] = {1, 2, 3, 4, 5, 6}; @@ -53,14 +54,16 @@ } template -void test_return_type() +TEST_CONSTEXPR_CXX20 void +test_return_type() { T *p = nullptr; static_assert( std::is_same_v(), std::multiplies<>()))> ); } -void test_move_only_types() +TEST_CONSTEXPR_CXX20 void +test_move_only_types() { MoveOnly ia[] = {{1}, {2}, {3}}; MoveOnly ib[] = {{1}, {2}, {3}}; @@ -70,7 +73,8 @@ [](const MoveOnly& lhs, const MoveOnly& rhs) { return MoveOnly{lhs.get() * rhs.get()}; }).get()); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 bool +test() { test_return_type(); test_return_type(); @@ -109,5 +113,14 @@ test_move_only_types(); - return 0; + return true; +} + +int main(int, char**) +{ + test(); +#if TEST_STD_VER > 17 + static_assert(test()); +#endif + return 0; } diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py --- a/libcxx/utils/generate_feature_test_macro_components.py +++ b/libcxx/utils/generate_feature_test_macro_components.py @@ -374,6 +374,10 @@ "values": { "c++2a": int(201811) }, "headers": ["array", "functional", "iterator", "string_view", "tuple", "utility"], "unimplemented": True, + }, { + "name": "__cpp_lib_constexpr_numeric", + "values": { "c++2a": int(201911) }, + "headers": ["numeric"], }, { "name": "__cpp_lib_bind_front", "values": { "c++2a": int(201811) }, diff --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html --- a/libcxx/www/cxx2a_status.html +++ b/libcxx/www/cxx2a_status.html @@ -198,7 +198,7 @@ P1394LWGRange constructor for std::span Belfast P1456LWGMove-only views Belfast P1622LWGMandating the Standard Library: Clause 32 - Thread support library Belfast - P1645LWGconstexpr for numeric algorithms Belfast + P1645LWGconstexpr for numeric algorithms BelfastComplete12.0 P1664LWGreconstructible_range - a concept for putting ranges back together Belfast P1686LWGMandating the Standard Library: Clause 27 - Time library Belfast P1690LWGRefinement Proposal for P0919 Heterogeneous lookup for unordered containers BelfastComplete12.0