Revert "[libc++] P1645 constexpr for <numeric>"

This reverts commit eb9b063539.

The commit fails to build on build bots using LLVM 8.
This commit is contained in:
Mark de Wever 2020-11-25 13:46:08 +01:00
parent ed242da0ff
commit ecabb39ca1
30 changed files with 247 additions and 806 deletions

View File

@ -196,8 +196,6 @@ Status
------------------------------------------------- -----------------
``__cpp_lib_constexpr_misc`` *unimplemented*
------------------------------------------------- -----------------
``__cpp_lib_constexpr_numeric`` ``201911L``
------------------------------------------------- -----------------
``__cpp_lib_constexpr_swap_algorithms`` *unimplemented*
------------------------------------------------- -----------------
``__cpp_lib_constexpr_utility`` ``201811L``

View File

@ -17,116 +17,115 @@ namespace std
{
template <class InputIterator, class T>
constexpr T // constexpr since C++20
T
accumulate(InputIterator first, InputIterator last, T init);
template <class InputIterator, class T, class BinaryOperation>
constexpr T // constexpr since C++20
T
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
template<class InputIterator>
constexpr typename iterator_traits<InputIterator>::value_type // constexpr since C++20
typename iterator_traits<InputIterator>::value_type
reduce(InputIterator first, InputIterator last); // C++17
template<class InputIterator, class T>
constexpr T // constexpr since C++20
T
reduce(InputIterator first, InputIterator last, T init); // C++17
template<class InputIterator, class T, class BinaryOperation>
constexpr T // constexpr since C++20
T
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17
template <class InputIterator1, class InputIterator2, class T>
constexpr T // constexpr since C++20
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
constexpr T // constexpr since C++20
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
template<class InputIterator1, class InputIterator2, class T>
constexpr T // constexpr since C++20
T
transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init); // C++17
template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
constexpr T // constexpr since C++20
T
transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17
template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
constexpr T // constexpr since C++20
T
transform_reduce(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template <class InputIterator, class OutputIterator>
constexpr OutputIterator // constexpr since C++20
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryOperation>
constexpr OutputIterator // constexpr since C++20
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
template<class InputIterator, class OutputIterator, class T>
constexpr OutputIterator // constexpr since C++20
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init); // C++17
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
constexpr OutputIterator // constexpr since C++20
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init, BinaryOperation binary_op); // C++17
template<class InputIterator, class OutputIterator>
constexpr OutputIterator // constexpr since C++20
OutputIterator
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17
template<class InputIterator, class OutputIterator, class BinaryOperation>
constexpr OutputIterator // constexpr since C++20
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op); // C++17
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
constexpr OutputIterator // constexpr since C++20
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op, T init); // C++17
template<class InputIterator, class OutputIterator, class T,
class BinaryOperation, class UnaryOperation>
constexpr OutputIterator // constexpr since C++20
OutputIterator
transform_exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template<class InputIterator, class OutputIterator,
class BinaryOperation, class UnaryOperation>
constexpr OutputIterator // constexpr since C++20
OutputIterator
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template<class InputIterator, class OutputIterator,
class BinaryOperation, class UnaryOperation, class T>
constexpr OutputIterator // constexpr since C++20
OutputIterator
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op,
T init); // C++17
template <class InputIterator, class OutputIterator>
constexpr OutputIterator // constexpr since C++20
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryOperation>
constexpr OutputIterator // constexpr since C++20
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
template <class ForwardIterator, class T>
constexpr void // constexpr since C++20
iota(ForwardIterator first, ForwardIterator last, T value);
void iota(ForwardIterator first, ForwardIterator last, T value);
template <class M, class N>
constexpr common_type_t<M,N> gcd(M m, N n); // C++17
@ -134,11 +133,9 @@ template <class M, class N>
template <class M, class N>
constexpr common_type_t<M,N> lcm(M m, N n); // C++17
template<class T>
constexpr T midpoint(T a, T b) noexcept; // C++20
template<class T>
constexpr T* midpoint(T* a, T* b); // C++20
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
} // std
@ -161,7 +158,7 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
@ -171,7 +168,7 @@ accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
}
template <class _InputIterator, class _Tp, class _BinaryOperation>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
{
@ -182,7 +179,7 @@ accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOpe
#if _LIBCPP_STD_VER > 14
template <class _InputIterator, class _Tp, class _BinaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
{
@ -192,7 +189,7 @@ reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
}
template <class _InputIterator, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
{
@ -200,7 +197,7 @@ reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
typename iterator_traits<_InputIterator>::value_type
reduce(_InputIterator __first, _InputIterator __last)
{
@ -210,7 +207,7 @@ reduce(_InputIterator __first, _InputIterator __last)
#endif
template <class _InputIterator1, class _InputIterator2, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
{
@ -220,7 +217,7 @@ inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2
}
template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
_Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
@ -232,7 +229,7 @@ inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2
#if _LIBCPP_STD_VER > 14
template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
transform_reduce(_InputIterator __first, _InputIterator __last,
_Tp __init, _BinaryOp __b, _UnaryOp __u)
@ -244,7 +241,7 @@ transform_reduce(_InputIterator __first, _InputIterator __last,
template <class _InputIterator1, class _InputIterator2,
class _Tp, class _BinaryOp1, class _BinaryOp2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2)
@ -255,7 +252,7 @@ transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
}
template <class _InputIterator1, class _InputIterator2, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_Tp
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init)
@ -266,7 +263,7 @@ transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
#endif
template <class _InputIterator, class _OutputIterator>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
@ -284,7 +281,7 @@ partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __res
}
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
_BinaryOperation __binary_op)
@ -304,7 +301,7 @@ partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __res
#if _LIBCPP_STD_VER > 14
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init, _BinaryOp __b)
@ -324,7 +321,7 @@ exclusive_scan(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _OutputIterator, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init)
@ -333,7 +330,6 @@ exclusive_scan(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b, _Tp __init)
{
@ -345,7 +341,6 @@ _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _OutputIterator, class _BinaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b)
{
@ -360,7 +355,6 @@ _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _OutputIterator>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
{
@ -369,7 +363,7 @@ _OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOp, class _UnaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init,
@ -390,9 +384,7 @@ transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
{
for (; __first != __last; ++__first, (void) ++__result) {
@ -404,9 +396,7 @@ transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
}
template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
{
if (__first != __last) {
@ -421,7 +411,7 @@ transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
#endif
template <class _InputIterator, class _OutputIterator>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
@ -440,7 +430,7 @@ adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterat
}
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
_BinaryOperation __binary_op)
@ -460,7 +450,7 @@ adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterat
}
template <class _ForwardIterator, class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
{

View File

@ -48,7 +48,6 @@ __cpp_lib_concepts 201806L <concepts>
__cpp_lib_constexpr_dynamic_alloc 201907L <memory>
__cpp_lib_constexpr_misc 201811L <array> <functional> <iterator>
<string_view> <tuple> <utility>
__cpp_lib_constexpr_numeric 201911L <numeric>
__cpp_lib_constexpr_swap_algorithms 201806L <algorithm>
__cpp_lib_constexpr_utility 201811L <utility>
__cpp_lib_destroying_delete 201806L <new>
@ -255,7 +254,6 @@ __cpp_lib_void_t 201411L <type_traits>
// # 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

View File

@ -14,7 +14,6 @@
// Test the feature test macros defined by <numeric>
/* 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]
@ -25,10 +24,6 @@
#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
@ -43,10 +38,6 @@
#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
@ -61,10 +52,6 @@
#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
@ -91,13 +78,6 @@
#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

View File

@ -42,7 +42,6 @@
__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]
@ -228,10 +227,6 @@
# 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
@ -624,10 +619,6 @@
# 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
@ -1134,10 +1125,6 @@
# 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
@ -1923,13 +1910,6 @@
# 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"

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator Iter, MoveConstructible T>
// requires HasPlus<T, Iter::reference>
// && HasAssign<T, HasPlus<T, Iter::reference>::result_type>
@ -22,14 +21,14 @@
#include "test_iterators.h"
template <class Iter, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter first, Iter last, T init, T x)
{
assert(std::accumulate(first, last, init) == x);
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -44,8 +43,7 @@ test()
test(Iter(ia), Iter(ia+sa), 10, 31);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*> >();
test<forward_iterator<const int*> >();
@ -53,14 +51,5 @@ test()
test<random_access_iterator<const int*> >();
test<const int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator Iter, MoveConstructible T,
// Callable<auto, const T&, Iter::reference> BinaryOperation>
// requires HasAssign<T, BinaryOperation::result_type>
@ -24,14 +23,14 @@
#include "test_iterators.h"
template <class Iter, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter first, Iter last, T init, T x)
{
assert(std::accumulate(first, last, init, std::multiplies<T>()) == x);
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -46,8 +45,7 @@ test()
test(Iter(ia), Iter(ia+sa), 10, 7200);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*> >();
test<forward_iterator<const int*> >();
@ -55,14 +53,5 @@ test()
test<random_access_iterator<const int*> >();
test<const int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator InIter,
// OutputIterator<auto, const InIter::value_type&> OutIter>
// requires HasMinus<InIter::value_type, InIter::value_type>
@ -26,7 +25,7 @@
#include "test_iterators.h"
template <class InIter, class OutIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {15, 10, 6, 3, 1};
@ -47,18 +46,18 @@ class X
{
int i_;
TEST_CONSTEXPR_CXX20 X& operator=(const X&);
X& operator=(const X&);
public:
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)
explicit X(int i) : i_(i) {}
X(const X& x) : i_(x.i_) {}
X& operator=(X&& x)
{
i_ = x.i_;
x.i_ = -1;
return *this;
}
TEST_CONSTEXPR_CXX20 friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
friend class Y;
};
@ -67,17 +66,16 @@ class Y
{
int i_;
TEST_CONSTEXPR_CXX20 Y& operator=(const Y&);
Y& operator=(const Y&);
public:
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_;}
explicit Y(int i) : i_(i) {}
Y(const Y& y) : i_(y.i_) {}
void operator=(const X& x) {i_ = x.i_;}
};
#endif
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*>, output_iterator<int*> >();
test<input_iterator<const int*>, forward_iterator<int*> >();
@ -115,14 +113,5 @@ test()
std::adjacent_difference(x, x+3, y);
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator InIter,
// OutputIterator<auto, const InIter::value_type&> OutIter,
// Callable<auto, const InIter::value_type&, const InIter::value_type&> BinaryOperation>
@ -27,7 +26,7 @@
#include "test_iterators.h"
template <class InIter, class OutIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {15, 10, 6, 3, 1};
@ -49,18 +48,18 @@ class X
{
int i_;
TEST_CONSTEXPR_CXX20 X& operator=(const X&);
X& operator=(const X&);
public:
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)
explicit X(int i) : i_(i) {}
X(const X& x) : i_(x.i_) {}
X& operator=(X&& x)
{
i_ = x.i_;
x.i_ = -1;
return *this;
}
TEST_CONSTEXPR_CXX20 friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
friend class Y;
};
@ -69,18 +68,17 @@ class Y
{
int i_;
TEST_CONSTEXPR_CXX20 Y& operator=(const Y&);
Y& operator=(const Y&);
public:
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_;}
explicit Y(int i) : i_(i) {}
Y(const Y& y) : i_(y.i_) {}
void operator=(const X& x) {i_ = x.i_;}
};
#endif
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*>, output_iterator<int*> >();
test<input_iterator<const int*>, forward_iterator<int*> >();
@ -118,14 +116,5 @@ test()
std::adjacent_difference(x, x+3, y, std::minus<X>());
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T>
// OutputIterator exclusive_scan(InputIterator first, InputIterator last,
// OutputIterator result, T init);
@ -17,7 +16,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -25,42 +23,27 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
template <class Iter1, class T, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, T init, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Not in place
std::exclusive_scan(first, last, v.begin(), init);
std::exclusive_scan(first, last, std::back_inserter(v), init);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// In place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::exclusive_scan(v.begin(), v.end(), v.begin(), init);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 3, 5, 7, 9};
@ -72,14 +55,13 @@ test()
test(Iter(ia), Iter(ia + i), 0, pRes, pRes + i);
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -87,7 +69,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -95,7 +77,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -104,8 +86,7 @@ basic_tests()
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
basic_tests();
@ -117,14 +98,5 @@ test()
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
// OutputIterator
// exclusive_scan(InputIterator first, InputIterator last,
@ -18,7 +17,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -26,43 +24,27 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
template <class Iter1, class T, class Op, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, T init, Op op, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Not in place
std::exclusive_scan(first, last, v.begin(), init, op);
std::exclusive_scan(first, last, std::back_inserter(v), init, op);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// In place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::exclusive_scan(v.begin(), v.end(), v.begin(), init, op);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 3, 5, 7, 9};
@ -78,8 +60,7 @@ test()
}
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
// All the iterator categories
test<input_iterator <const int*> >();
@ -91,20 +72,10 @@ test()
// Make sure that the calculations are done using the init typedef
{
std::array<unsigned char, 10> v;
std::vector<unsigned char> v(10);
std::iota(v.begin(), v.end(), static_cast<unsigned char>(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<size_t> res;
std::exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>());
#else
std::array<size_t, 10> res;
std::exclusive_scan(v.begin(), v.end(), res.begin(), 1, std::multiplies<>());
#endif
assert(res.size() == 10);
size_t j = 1;
@ -116,14 +87,5 @@ test()
}
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T>
// OutputIterator inclusive_scan(InputIterator first, InputIterator last,
// OutputIterator result, T init);
@ -17,7 +16,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -25,43 +23,27 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
template <class Iter1, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Not in place
std::inclusive_scan(first, last, v.begin());
std::inclusive_scan(first, last, std::back_inserter(v));
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// In place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::inclusive_scan(v.begin(), v.end(), v.begin());
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 3, 5, 7, 9};
@ -73,14 +55,13 @@ test()
test(Iter(ia), Iter(ia + i), pRes, pRes + i);
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -88,7 +69,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -96,7 +77,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -104,24 +85,13 @@ basic_tests()
}
{
// 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<size_t> v, res;
std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res));
#else
std::array<size_t, 0> v, res;
std::inclusive_scan(v.begin(), v.end(), res.begin());
#endif
assert(res.empty());
}
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
basic_tests();
@ -133,14 +103,5 @@ test()
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
// OutputIterator
// inclusive_scan(InputIterator first, InputIterator last,
@ -18,7 +17,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -26,43 +24,27 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
template <class Iter1, class Op, class Iter2>
TEST_CONSTEXPR_CXX20 void
template <class Iter1, class T, class Op, class Iter2>
void
test(Iter1 first, Iter1 last, Op op, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Not in place
std::inclusive_scan(first, last, v.begin(), op);
std::inclusive_scan(first, last, std::back_inserter(v), op);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// In place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::inclusive_scan(v.begin(), v.end(), v.begin(), op);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 3, 5, 7, 9};
@ -78,14 +60,13 @@ test()
}
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -93,7 +74,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -101,7 +82,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -109,43 +90,26 @@ basic_tests()
}
{
// 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<size_t> v, res;
std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>());
#else
std::array<size_t, 0> v, res;
std::inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>());
#endif
assert(res.empty());
}
}
TEST_CONSTEXPR_CXX20 bool
test()
{
basic_tests();
// All the iterator categories
test<input_iterator <const int*> >();
test<forward_iterator <const int*> >();
test<bidirectional_iterator<const int*> >();
test<random_access_iterator<const int*> >();
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
basic_tests();
// All the iterator categories
// test<input_iterator <const int*> >();
// test<forward_iterator <const int*> >();
// test<bidirectional_iterator<const int*> >();
// test<random_access_iterator<const int*> >();
// test<const int*>();
// test< int*>();
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
// OutputIterator
// inclusive_scan(InputIterator first, InputIterator last,
@ -18,7 +17,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -26,43 +24,27 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
template <class Iter1, class T, class Op, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, Op op, T init, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Not in place
std::inclusive_scan(first, last, v.begin(), op, init);
std::inclusive_scan(first, last, std::back_inserter(v), op, init);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// In place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::inclusive_scan(v.begin(), v.end(), v.begin(), op, init);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 3, 5, 7, 9};
@ -78,14 +60,13 @@ test()
}
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -93,7 +74,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -101,7 +82,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -109,37 +90,17 @@ basic_tests()
}
{
// 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<size_t> v, res;
std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), size_t{40});
#else
std::array<size_t, 0> 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::array<unsigned char, 10> v;
std::vector<unsigned char> v(10);
std::iota(v.begin(), v.end(), static_cast<unsigned char>(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<size_t> res;
std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), size_t{1});
#else
std::array<size_t, 10> res;
std::inclusive_scan(v.begin(), v.end(), res.begin(), std::multiplies<>(), size_t{1});
#endif
assert(res.size() == 10);
size_t j = 1;
@ -152,9 +113,10 @@ basic_tests()
}
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
basic_tests();
// All the iterator categories
@ -165,14 +127,6 @@ test()
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator Iter1, InputIterator Iter2, MoveConstructible T>
// requires HasMultiply<Iter1::reference, Iter2::reference>
// && HasPlus<T, HasMultiply<Iter1::reference, Iter2::reference>::result_type>
@ -26,14 +25,14 @@
#include "test_iterators.h"
template <class Iter1, class Iter2, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x)
{
assert(std::inner_product(first1, last1, first2, init) == x);
}
template <class Iter1, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int a[] = {1, 2, 3, 4, 5, 6};
@ -49,8 +48,7 @@ test()
test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 66);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*>, input_iterator<const int*> >();
test<input_iterator<const int*>, forward_iterator<const int*> >();
@ -82,14 +80,5 @@ test()
test<const int*, random_access_iterator<const int*> >();
test<const int*, const int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator Iter1, InputIterator Iter2, MoveConstructible T,
// class BinaryOperation1,
// Callable<auto, Iter1::reference, Iter2::reference> BinaryOperation2>
@ -28,7 +27,7 @@
#include "test_iterators.h"
template <class Iter1, class Iter2, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x)
{
assert(std::inner_product(first1, last1, first2, init,
@ -36,7 +35,7 @@ test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x)
}
template <class Iter1, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int a[] = {1, 2, 3, 4, 5, 6};
@ -52,8 +51,7 @@ test()
test(Iter1(a), Iter1(a+sa), Iter2(b), 10, 1176490);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*>, input_iterator<const int*> >();
test<input_iterator<const int*>, forward_iterator<const int*> >();
@ -85,14 +83,5 @@ test()
test<const int*, random_access_iterator<const int*> >();
test<const int*, const int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <class ForwardIterator, class T>
// void iota(ForwardIterator first, ForwardIterator last, T value);
@ -19,7 +18,7 @@
#include "test_iterators.h"
template <class InIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5};
@ -30,22 +29,12 @@ test()
assert(ia[i] == ir[i]);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<forward_iterator<int*> >();
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template <InputIterator InIter, OutputIterator<auto, const InIter::value_type&> OutIter>
// requires HasPlus<InIter::value_type, InIter::reference>
// && HasAssign<InIter::value_type,
@ -24,7 +23,7 @@
#include "test_iterators.h"
template <class InIter, class OutIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5};
@ -37,8 +36,7 @@ test()
assert(ib[i] == ir[i]);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*>, output_iterator<int*> >();
test<input_iterator<const int*>, forward_iterator<int*> >();
@ -70,14 +68,5 @@ test()
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -8,7 +8,6 @@
// <numeric>
// Became constexpr in C++20
// template<InputIterator InIter,
// OutputIterator<auto, const InIter::value_type&> OutIter,
// Callable<auto, const InIter::value_type&, InIter::reference> BinaryOperation>
@ -26,7 +25,7 @@
#include "test_iterators.h"
template <class InIter, class OutIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5};
@ -39,8 +38,7 @@ test()
assert(ib[i] == ir[i]);
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test<input_iterator<const int*>, output_iterator<int*> >();
test<input_iterator<const int*>, forward_iterator<int*> >();
@ -72,14 +70,5 @@ test()
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator>
// typename iterator_traits<InputIterator>::value_type
// reduce(InputIterator first, InputIterator last);
@ -21,7 +20,7 @@
#include "test_iterators.h"
template <class Iter, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter first, Iter last, T x)
{
static_assert( std::is_same_v<typename std::iterator_traits<decltype(first)>::value_type,
@ -30,7 +29,7 @@ test(Iter first, Iter last, T x)
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -42,15 +41,13 @@ test()
}
template <typename T>
TEST_CONSTEXPR_CXX20 void
test_return_type()
void test_return_type()
{
T *p = nullptr;
static_assert( std::is_same_v<T, decltype(std::reduce(p, p))> );
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test_return_type<char>();
test_return_type<int>();
@ -64,14 +61,5 @@ test()
test<random_access_iterator<const int*> >();
test<const int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class T>
// T reduce(InputIterator first, InputIterator last, T init);
@ -20,7 +19,7 @@
#include "test_iterators.h"
template <class Iter, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter first, Iter last, T init, T x)
{
static_assert( std::is_same_v<T, decltype(std::reduce(first, last, init))> );
@ -28,7 +27,7 @@ test(Iter first, Iter last, T init, T x)
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -44,15 +43,13 @@ test()
}
template <typename T, typename Init>
TEST_CONSTEXPR_CXX20 void
test_return_type()
void test_return_type()
{
T *p = nullptr;
static_assert( std::is_same_v<Init, decltype(std::reduce(p, p, Init{}))> );
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test_return_type<char, int>();
test_return_type<int, int>();
@ -68,14 +65,5 @@ test()
test<random_access_iterator<const int*> >();
test<const int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class T, class BinaryOperation>
// T reduce(InputIterator first, InputIterator last, T init, BinaryOperation op);
@ -20,7 +19,7 @@
#include "test_iterators.h"
template <class Iter, class T, class Op>
TEST_CONSTEXPR_CXX20 void
void
test(Iter first, Iter last, T init, Op op, T x)
{
static_assert( std::is_same_v<T, decltype(std::reduce(first, last, init, op))>, "" );
@ -28,7 +27,7 @@ test(Iter first, Iter last, T init, Op op, T x)
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -44,15 +43,13 @@ test()
}
template <typename T, typename Init>
TEST_CONSTEXPR_CXX20 void
test_return_type()
void test_return_type()
{
T *p = nullptr;
static_assert( std::is_same_v<Init, decltype(std::reduce(p, p, Init{}, std::plus<>()))>, "" );
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test_return_type<char, int>();
test_return_type<int, int>();
@ -75,14 +72,5 @@ test()
assert(res == 40320); // 8! will not fit into a char
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T,
// class BinaryOperation, class UnaryOperation>
// OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last,
@ -20,7 +19,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -28,10 +26,6 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
struct add_one {
template <typename T>
@ -41,37 +35,24 @@ struct add_one {
};
template <class Iter1, class BOp, class UOp, class T, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Test not in-place
std::transform_exclusive_scan(first, last, v.begin(), init, bop, uop);
std::transform_exclusive_scan(first, last, std::back_inserter(v), init, bop, uop);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// Test in-place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), init, bop, uop);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = { 1, 3, 5, 7, 9 };
@ -105,14 +86,13 @@ test()
}
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -120,7 +100,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -128,7 +108,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -136,37 +116,17 @@ basic_tests()
}
{
// 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<size_t> v, res;
std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{40}, std::plus<>(), add_one{});
#else
std::array<size_t, 0> 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::array<unsigned char, 10> v;
std::vector<unsigned char> v(10);
std::iota(v.begin(), v.end(), static_cast<unsigned char>(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<size_t> res;
std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), size_t{1}, std::multiplies<>(), add_one{});
#else
std::array<size_t, 10> 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;
@ -179,8 +139,7 @@ basic_tests()
}
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
basic_tests();
@ -192,14 +151,5 @@ test()
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -10,7 +10,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T,
// class BinaryOperation, class UnaryOperation>
// OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
@ -21,7 +20,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -29,10 +27,6 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
struct add_one {
template <typename T>
@ -42,37 +36,24 @@ struct add_one {
};
template <class Iter1, class BOp, class UOp, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, BOp bop, UOp uop, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Test not in-place
std::transform_inclusive_scan(first, last, v.begin(), bop, uop);
std::transform_inclusive_scan(first, last, std::back_inserter(v), bop, uop);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// Test in-place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), bop, uop);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = { 1, 3, 5, 7, 9 };
@ -94,14 +75,13 @@ test()
}
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -109,7 +89,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -117,7 +97,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -125,24 +105,13 @@ basic_tests()
}
{
// 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<size_t> v, res;
std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{});
#else
std::array<size_t, 0> v, res;
std::transform_inclusive_scan(v.begin(), v.end(), res.begin(), std::plus<>(), add_one{});
#endif
assert(res.empty());
}
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
basic_tests();
@ -154,14 +123,5 @@ test()
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template<class InputIterator, class OutputIterator, class T,
// class BinaryOperation, class UnaryOperation>
// OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
@ -21,7 +20,6 @@
#include <numeric>
#include <algorithm>
#include <array>
#include <cassert>
#include <functional>
#include <iterator>
@ -29,10 +27,6 @@
#include "test_macros.h"
#include "test_iterators.h"
// FIXME Remove constexpr vector workaround introduced in D90569
#if TEST_STD_VER > 17
#include <span>
#endif
struct add_one {
template <typename T>
@ -42,37 +36,24 @@ struct add_one {
};
template <class Iter1, class BOp, class UOp, class T, class Iter2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first, Iter1 last, BOp bop, UOp uop, T init, Iter2 rFirst, Iter2 rLast)
{
// 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<typename std::iterator_traits<Iter1>::value_type> v(size);
#else
assert((size <= 5) && "Increment the size of the array");
typename std::iterator_traits<Iter1>::value_type b[5];
std::span<typename std::iterator_traits<Iter1>::value_type> v{b, size};
#endif
std::vector<typename std::iterator_traits<Iter1>::value_type> v;
// Test not in-place
std::transform_inclusive_scan(first, last, v.begin(), bop, uop, init);
std::transform_inclusive_scan(first, last, std::back_inserter(v), bop, uop, init);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
// Test in-place
std::copy(first, last, v.begin());
v.clear();
v.assign(first, last);
std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), bop, uop, init);
assert(std::equal(v.begin(), v.end(), rFirst, rLast));
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = { 1, 3, 5, 7, 9 };
@ -106,14 +87,13 @@ test()
}
}
constexpr size_t triangle(size_t n) { return n*(n+1)/2; }
size_t triangle(size_t n) { return n*(n+1)/2; }
// Basic sanity
TEST_CONSTEXPR_CXX20 void
basic_tests()
void basic_tests()
{
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -121,7 +101,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -129,7 +109,7 @@ basic_tests()
}
{
std::array<size_t, 10> v;
std::vector<size_t> v(10);
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)
@ -137,37 +117,17 @@ basic_tests()
}
{
// 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<size_t> v, res;
std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_one{}, size_t{1});
#else
std::array<size_t, 0> 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::array<unsigned char, 10> v;
std::vector<unsigned char> v(10);
std::iota(v.begin(), v.end(), static_cast<unsigned char>(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<size_t> res;
std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), add_one{}, size_t{1});
#else
std::array<size_t, 10> 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;
@ -180,8 +140,7 @@ basic_tests()
}
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
basic_tests();
@ -193,14 +152,5 @@ test()
test<const int*>();
test< int*>();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template <class InputIterator1, class T,
// class BinaryOperation, class UnaryOperation>
// T transform_reduce(InputIterator1 first1, InputIterator1 last1,
@ -42,7 +41,7 @@ struct twice
};
template <class Iter1, class T, class BOp, class UOp>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first1, Iter1 last1, T init, BOp bOp, UOp uOp, T x)
{
static_assert( std::is_same_v<T,
@ -51,7 +50,7 @@ test(Iter1 first1, Iter1 last1, T init, BOp bOp, UOp uOp, T x)
}
template <class Iter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -77,16 +76,14 @@ test()
}
template <typename T, typename Init>
TEST_CONSTEXPR_CXX20 void
test_return_type()
void test_return_type()
{
T *p = nullptr;
static_assert( std::is_same_v<Init,
decltype(std::transform_reduce(p, p, Init{}, std::plus<>(), identity()))> );
}
TEST_CONSTEXPR_CXX20 void
test_move_only_types()
void test_move_only_types()
{
MoveOnly ia[] = {{1}, {2}, {3}};
assert(60 ==
@ -95,8 +92,7 @@ test_move_only_types()
[](const MoveOnly& target) { return MoveOnly{target.get() * 10}; }).get());
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test_return_type<char, int>();
test_return_type<int, int>();
@ -123,14 +119,5 @@ test()
test_move_only_types();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template <class InputIterator1, class InputIterator2, class T>
// T transform_reduce(InputIterator1 first1, InputIterator1 last1,
// InputIterator2 first2, T init);
@ -24,7 +23,7 @@
#include "test_iterators.h"
template <class Iter1, class Iter2, class T>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x)
{
static_assert( std::is_same_v<T,
@ -33,7 +32,7 @@ test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x)
}
template <class SIter, class UIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -52,16 +51,14 @@ test()
}
template <typename T, typename Init>
TEST_CONSTEXPR_CXX20 void
test_return_type()
void test_return_type()
{
T *p = nullptr;
static_assert( std::is_same_v<Init,
decltype(std::transform_reduce(p, p, p, Init{}))> );
}
TEST_CONSTEXPR_CXX20 void
test_move_only_types()
void test_move_only_types()
{
MoveOnly ia[] = {{1}, {2}, {3}};
MoveOnly ib[] = {{1}, {2}, {3}};
@ -69,8 +66,7 @@ test_move_only_types()
std::transform_reduce(std::begin(ia), std::end(ia), std::begin(ib), MoveOnly{0}).get());
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test_return_type<char, int>();
test_return_type<int, int>();
@ -109,14 +105,5 @@ test()
test_move_only_types();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -9,7 +9,6 @@
// <numeric>
// UNSUPPORTED: c++03, c++11, c++14
// Became constexpr in C++20
// template <class InputIterator1, class InputIterator2, class T,
// class BinaryOperation1, class BinaryOperation2>
// T transform_reduce(InputIterator1 first1, InputIterator1 last1,
@ -26,7 +25,7 @@
#include "test_iterators.h"
template <class Iter1, class Iter2, class T, class Op1, class Op2>
TEST_CONSTEXPR_CXX20 void
void
test(Iter1 first1, Iter1 last1, Iter2 first2, T init, Op1 op1, Op2 op2, T x)
{
static_assert( std::is_same_v<T,
@ -35,7 +34,7 @@ test(Iter1 first1, Iter1 last1, Iter2 first2, T init, Op1 op1, Op2 op2, T x)
}
template <class SIter, class UIter>
TEST_CONSTEXPR_CXX20 void
void
test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
@ -54,16 +53,14 @@ test()
}
template <typename T, typename Init>
TEST_CONSTEXPR_CXX20 void
test_return_type()
void test_return_type()
{
T *p = nullptr;
static_assert( std::is_same_v<Init,
decltype(std::transform_reduce(p, p, p, Init{}, std::plus<>(), std::multiplies<>()))> );
}
TEST_CONSTEXPR_CXX20 void
test_move_only_types()
void test_move_only_types()
{
MoveOnly ia[] = {{1}, {2}, {3}};
MoveOnly ib[] = {{1}, {2}, {3}};
@ -73,8 +70,7 @@ test_move_only_types()
[](const MoveOnly& lhs, const MoveOnly& rhs) { return MoveOnly{lhs.get() * rhs.get()}; }).get());
}
TEST_CONSTEXPR_CXX20 bool
test()
int main(int, char**)
{
test_return_type<char, int>();
test_return_type<int, int>();
@ -113,14 +109,5 @@ test()
test_move_only_types();
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
return 0;
}

View File

@ -374,10 +374,6 @@ feature_test_macros = sorted([ add_version_header(x) for x in [
"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) },

View File

@ -198,7 +198,7 @@
<tr><td><a href="https://wg21.link/P1394">P1394</a></td><td>LWG</td><td>Range constructor for std::span </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1456">P1456</a></td><td>LWG</td><td>Move-only views </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1622">P1622</a></td><td>LWG</td><td>Mandating the Standard Library: Clause 32 - Thread support library </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1645">P1645</a></td><td>LWG</td><td>constexpr for numeric algorithms </td><td>Belfast</td><td>Complete</td><td>12.0</td></tr>
<tr><td><a href="https://wg21.link/P1645">P1645</a></td><td>LWG</td><td>constexpr for numeric algorithms </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1664">P1664</a></td><td>LWG</td><td>reconstructible_range - a concept for putting ranges back together </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1686">P1686</a></td><td>LWG</td><td>Mandating the Standard Library: Clause 27 - Time library </td><td>Belfast</td><td><i> </i></td><td></td></tr>
<tr><td><a href="https://wg21.link/P1690">P1690</a></td><td>LWG</td><td>Refinement Proposal for P0919 Heterogeneous lookup for unordered containers </td><td>Belfast</td><td>Complete</td><td>12.0</td></tr>