From 1e1195dce5bc07a2f925c3e3cc3a62534fffa82d Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Sat, 6 Jan 2018 02:18:20 +0000 Subject: [PATCH] [libcxx] [test] Remove nonstandard things and resolve warnings in Xxx_scan tests Reviewed as https://reviews.llvm.org/D41748 * These tests use function objects from functional, back_inserter from iterator, and equal from algorithm, so add those headers. * The use of iota targeting vector with an int parameter triggers warnings on MSVC++ assigning an into a unsigned char&; so change the parameter to unsigned char with a static_cast. * Avoid naming unary_function in identity here as that is removed in '17. (This also fixes naming _VSTD, _NOEXCEPT_, and other libcxx-isms) * Change the predicate in the transform tests to add_ten so that problems with multiple application are caught. llvm-svn: 321922 --- .../exclusive.scan/exclusive_scan.pass.cpp | 5 +- .../exclusive_scan_init_op.pass.cpp | 7 ++- .../inclusive.scan/inclusive_scan.pass.cpp | 5 +- .../inclusive.scan/inclusive_scan_op.pass.cpp | 5 +- .../inclusive_scan_op_init.pass.cpp | 7 ++- ...sform_exclusive_scan_init_bop_uop.pass.cpp | 62 +++++++++---------- .../transform_inclusive_scan_bop_uop.pass.cpp | 46 ++++++-------- ...sform_inclusive_scan_bop_uop_init.pass.cpp | 62 +++++++++---------- 8 files changed, 98 insertions(+), 101 deletions(-) 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 index 34181f508e2a..0cf6f2345e35 100644 --- 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 @@ -16,8 +16,11 @@ // #include -#include +#include #include +#include +#include +#include #include "test_iterators.h" 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 index c15cb1661e25..c67716976492 100644 --- 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 @@ -17,8 +17,11 @@ // T init, BinaryOperation binary_op); // C++17 #include -#include +#include #include +#include +#include +#include #include "test_iterators.h" @@ -70,7 +73,7 @@ int main() // Make sure that the calculations are done using the init typedef { std::vector v(10); - std::iota(v.begin(), v.end(), 1); + std::iota(v.begin(), v.end(), static_cast(1)); std::vector res; std::exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>()); 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 index 5c422300e343..a6ebe86c9885 100644 --- 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 @@ -16,8 +16,11 @@ // #include -#include +#include #include +#include +#include +#include #include "test_iterators.h" 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 index 2c6eacc1682f..ee1c489343ef 100644 --- 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 @@ -17,9 +17,12 @@ // BinaryOperation binary_op); // C++17 #include -#include +#include #include +#include #include +#include +#include #include "test_iterators.h" 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 index 653578055c69..d0e1eb133223 100644 --- 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 @@ -17,8 +17,11 @@ // BinaryOperation binary_op, T init); // C++17 #include -#include +#include #include +#include +#include +#include #include "test_iterators.h" @@ -95,7 +98,7 @@ void basic_tests() // Make sure that the calculations are done using the init typedef { std::vector v(10); - std::iota(v.begin(), v.end(), 1); + std::iota(v.begin(), v.end(), static_cast(1)); std::vector res; std::inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), 1); 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 index 4964e8e884bd..ca5a89790375 100644 --- 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 @@ -19,26 +19,20 @@ #include -#include +#include #include +#include #include +#include +#include #include "test_iterators.h" -template -struct identity : std::unary_function -{ - constexpr const T& operator()(const T& x) const { return x;} -}; - -template <> -struct identity -{ - template - constexpr auto operator()(T&& x) const - _NOEXCEPT_(noexcept(_VSTD::forward(x))) - -> decltype (_VSTD::forward(x)) - { return _VSTD::forward(x); } +struct add_ten { + template + constexpr auto operator()(T x) const noexcept { + return static_cast(x + 10); + } }; template @@ -63,14 +57,14 @@ void test() { int ia[] = { 1, 3, 5, 7, 9}; - const int pResI0[] = { 0, 1, 4, 9, 16}; // with identity + const int pResI0[] = { 0, 11, 24, 39, 56}; // with add_ten const int mResI0[] = { 0, 0, 0, 0, 0}; const int pResN0[] = { 0, -1, -4, -9, -16}; // with negate const int mResN0[] = { 0, 0, 0, 0, 0}; - const int pResI2[] = { 2, 3, 6, 11, 18}; // with identity - const int mResI2[] = { 2, 2, 6, 30, 210}; - const int pResN2[] = { 2, 1, -2, -7, -14}; // with negate - const int mResN2[] = { 2, -2, 6, -30, 210}; + const int pResI2[] = { 2, 13, 26, 41, 58}; // with add_ten + const int mResI2[] = { 2, 22, 286, 4290, 72930}; + const int pResN2[] = { 2, 1, -2, -7, -14}; // with negate + const int mResN2[] = { 2, -2, 6, -30, 210}; const unsigned sa = sizeof(ia) / sizeof(ia[0]); static_assert(sa == sizeof(pResI0) / sizeof(pResI0[0])); // just to be sure static_assert(sa == sizeof(mResI0) / sizeof(mResI0[0])); // just to be sure @@ -82,12 +76,12 @@ test() static_assert(sa == sizeof(mResN2) / sizeof(mResN2[0])); // just to be sure for (unsigned int i = 0; i < sa; ++i ) { - test(Iter(ia), Iter(ia + i), std::plus<>(), identity<>(), 0, pResI0, pResI0 + i); - test(Iter(ia), Iter(ia + i), std::multiplies<>(), identity<>(), 0, mResI0, mResI0 + i); + test(Iter(ia), Iter(ia + i), std::plus<>(), add_ten{}, 0, pResI0, pResI0 + i); + test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_ten{}, 0, mResI0, mResI0 + i); test(Iter(ia), Iter(ia + i), std::plus<>(), std::negate<>(), 0, pResN0, pResN0 + i); test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 0, mResN0, mResN0 + i); - test(Iter(ia), Iter(ia + i), std::plus<>(), identity<>(), 2, pResI2, pResI2 + i); - test(Iter(ia), Iter(ia + i), std::multiplies<>(), identity<>(), 2, mResI2, mResI2 + i); + test(Iter(ia), Iter(ia + i), std::plus<>(), add_ten{}, 2, pResI2, pResI2 + i); + test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_ten{}, 2, mResI2, mResI2 + i); test(Iter(ia), Iter(ia + i), std::plus<>(), std::negate<>(), 2, pResN2, pResN2 + i); test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 2, mResN2, mResN2 + i); } @@ -101,46 +95,46 @@ void basic_tests() { std::vector v(10); std::fill(v.begin(), v.end(), 3); - std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), 50, std::plus<>(), identity<>()); + std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), 50, std::plus<>(), add_ten{}); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == 50 + (int) i * 3); + assert(v[i] == 50 + (int) i * 13); } { std::vector v(10); std::iota(v.begin(), v.end(), 0); - std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), 30, std::plus<>(), identity<>()); + std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), 30, std::plus<>(), add_ten{}); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == 30 + triangle(i-1)); + assert(v[i] == 30 + triangle(i - 1) + i * 10); } { std::vector v(10); std::iota(v.begin(), v.end(), 1); - std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), 40, std::plus<>(), identity<>()); + std::transform_exclusive_scan(v.begin(), v.end(), v.begin(), 40, std::plus<>(), add_ten{}); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == 40 + triangle(i)); + assert(v[i] == 40 + triangle(i) + i * 10); } { std::vector v, res; - std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 40, std::plus<>(), identity<>()); + std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 40, std::plus<>(), add_ten{}); assert(res.empty()); } // Make sure that the calculations are done using the init typedef { std::vector v(10); - std::iota(v.begin(), v.end(), 1); + std::iota(v.begin(), v.end(), static_cast(1)); std::vector res; - std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>(), identity<>()); + std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, std::multiplies<>(), add_ten{}); assert(res.size() == 10); int j = 1; assert(res[0] == 1); for (size_t i = 1; i < res.size(); ++i) { - j *= i; + j *= i + 10; assert(res[i] == j); } } 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 index d15defc2cabc..a8d4d73849f9 100644 --- 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 @@ -20,26 +20,20 @@ #include -#include +#include #include +#include #include +#include +#include #include "test_iterators.h" -template -struct identity : std::unary_function -{ - constexpr const T& operator()(const T& x) const { return x;} -}; - -template <> -struct identity -{ - template - constexpr auto operator()(T&& x) const - _NOEXCEPT_(noexcept(_VSTD::forward(x))) - -> decltype (_VSTD::forward(x)) - { return _VSTD::forward(x); } +struct add_ten { + template + constexpr auto operator()(T x) const noexcept { + return static_cast(x + 10); + } }; template @@ -64,8 +58,8 @@ void test() { int ia[] = { 1, 3, 5, 7, 9}; - const int pResI0[] = { 1, 4, 9, 16, 25}; // with identity - const int mResI0[] = { 1, 3, 15, 105, 945}; + const int pResI0[] = { 11, 24, 39, 56, 75}; // with add_ten + const int mResI0[] = { 11, 143, 2145, 36465, 692835}; const int pResN0[] = { -1, -4, -9, -16, -25}; // with negate const int mResN0[] = { -1, 3, -15, 105, -945}; const unsigned sa = sizeof(ia) / sizeof(ia[0]); @@ -75,8 +69,8 @@ test() static_assert(sa == sizeof(mResN0) / sizeof(mResN0[0])); // just to be sure for (unsigned int i = 0; i < sa; ++i ) { - test(Iter(ia), Iter(ia + i), std::plus<>(), identity<>(), pResI0, pResI0 + i); - test(Iter(ia), Iter(ia + i), std::multiplies<>(), identity<>(), mResI0, mResI0 + i); + test(Iter(ia), Iter(ia + i), std::plus<>(), add_ten{}, pResI0, pResI0 + i); + test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_ten{}, mResI0, mResI0 + i); test(Iter(ia), Iter(ia + i), std::plus<>(), std::negate<>(), pResN0, pResN0 + i); test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), mResN0, mResN0 + i); } @@ -90,32 +84,32 @@ void basic_tests() { std::vector v(10); std::fill(v.begin(), v.end(), 3); - std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), identity<>()); + std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_ten{}); std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, " ")); std::cout << std::endl; for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == (int)(i+1) * 3); + assert(v[i] == (int)(i+1) * 13); } { std::vector v(10); std::iota(v.begin(), v.end(), 0); - std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), identity<>()); + std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_ten{}); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == triangle(i)); + assert(v[i] == triangle(i) + (i + 1) * 10); } { std::vector v(10); std::iota(v.begin(), v.end(), 1); - std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), identity<>()); + std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_ten{}); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == triangle(i + 1)); + assert(v[i] == triangle(i + 1) + (i + 1) * 10); } { std::vector v, res; - std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), identity<>()); + std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_ten{}); assert(res.empty()); } } 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 index b38b9a5afedf..f4e6c0a99c92 100644 --- 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 @@ -20,25 +20,19 @@ #include -#include +#include #include +#include +#include +#include #include "test_iterators.h" -template -struct identity : std::unary_function -{ - constexpr const T& operator()(const T& x) const { return x;} -}; - -template <> -struct identity -{ - template - constexpr auto operator()(T&& x) const - _NOEXCEPT_(noexcept(_VSTD::forward(x))) - -> decltype (_VSTD::forward(x)) - { return _VSTD::forward(x); } +struct add_ten { + template + constexpr auto operator()(T x) const noexcept { + return static_cast(x + 10); + } }; template @@ -63,12 +57,12 @@ void test() { int ia[] = { 1, 3, 5, 7, 9}; - const int pResI0[] = { 1, 4, 9, 16, 25}; // with identity + const int pResI0[] = { 11, 24, 39, 56, 75}; // with add_ten const int mResI0[] = { 0, 0, 0, 0, 0}; const int pResN0[] = { -1, -4, -9, -16, -25}; // with negate const int mResN0[] = { 0, 0, 0, 0, 0}; - const int pResI2[] = { 3, 6, 11, 18, 27}; // with identity - const int mResI2[] = { 2, 6, 30, 210, 1890}; + const int pResI2[] = { 13, 26, 41, 58, 77}; // with add_ten + const int mResI2[] = { 22, 286, 4290, 72930, 1385670}; const int pResN2[] = { 1, -2, -7, -14, -23}; // with negate const int mResN2[] = { -2, 6, -30, 210, -1890}; const unsigned sa = sizeof(ia) / sizeof(ia[0]); @@ -82,12 +76,12 @@ test() static_assert(sa == sizeof(mResN2) / sizeof(mResN2[0])); // just to be sure for (unsigned int i = 0; i < sa; ++i ) { - test(Iter(ia), Iter(ia + i), std::plus<>(), identity<>(), 0, pResI0, pResI0 + i); - test(Iter(ia), Iter(ia + i), std::multiplies<>(), identity<>(), 0, mResI0, mResI0 + i); + test(Iter(ia), Iter(ia + i), std::plus<>(), add_ten{}, 0, pResI0, pResI0 + i); + test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_ten{}, 0, mResI0, mResI0 + i); test(Iter(ia), Iter(ia + i), std::plus<>(), std::negate<>(), 0, pResN0, pResN0 + i); test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 0, mResN0, mResN0 + i); - test(Iter(ia), Iter(ia + i), std::plus<>(), identity<>(), 2, pResI2, pResI2 + i); - test(Iter(ia), Iter(ia + i), std::multiplies<>(), identity<>(), 2, mResI2, mResI2 + i); + test(Iter(ia), Iter(ia + i), std::plus<>(), add_ten{}, 2, pResI2, pResI2 + i); + test(Iter(ia), Iter(ia + i), std::multiplies<>(), add_ten{}, 2, mResI2, mResI2 + i); test(Iter(ia), Iter(ia + i), std::plus<>(), std::negate<>(), 2, pResN2, pResN2 + i); test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 2, mResN2, mResN2 + i); } @@ -101,46 +95,46 @@ void basic_tests() { std::vector v(10); std::fill(v.begin(), v.end(), 3); - std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), identity<>(), 50); + std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_ten{}, 50); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == 50 + (int) (i + 1) * 3); + assert(v[i] == 50 + (int) (i + 1) * 13); } { std::vector v(10); std::iota(v.begin(), v.end(), 0); - std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), identity<>(), 30); + std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_ten{}, 30); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == 30 + triangle(i)); + assert(v[i] == 30 + triangle(i) + (i + 1) * 10); } { std::vector v(10); std::iota(v.begin(), v.end(), 1); - std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), identity<>(), 40); + std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_ten{}, 40); for (size_t i = 0; i < v.size(); ++i) - assert(v[i] == 40 + triangle(i + 1)); + assert(v[i] == 40 + triangle(i + 1) + (i + 1) * 10); } { std::vector v, res; - std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), identity<>(), 1); + std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::plus<>(), add_ten{}, 1); assert(res.empty()); } // Make sure that the calculations are done using the init typedef { std::vector v(10); - std::iota(v.begin(), v.end(), 1); + std::iota(v.begin(), v.end(), static_cast(1)); std::vector res; - std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), identity<>(), 1); + std::transform_inclusive_scan(v.begin(), v.end(), std::back_inserter(res), std::multiplies<>(), add_ten{}, 1); assert(res.size() == 10); - int j = 1; - assert(res[0] == 1); + int j = 11; + assert(res[0] == 11); for (size_t i = 1; i < res.size(); ++i) { - j *= i + 1; + j *= i + 11; assert(res[i] == j); } }