[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
BillyONeal accepted this revision. BillyONeal added a comment. This revision is now accepted and ready to land. It actually looks like I accidentally committed this back in January so I'm going to close this :) https://reviews.llvm.org/D41748 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
BillyONeal added a comment. @EricWF / @mclow.lists Any chance you could take a look sometime soon? https://reviews.llvm.org/D41748 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
CaseyCarter added inline comments. Comment at: test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp:33 +template +constexpr auto operator()(T x) const noexcept { +return static_cast(x + 10); Although it doesn't matter to these tests, this notably doesn't have return type SFINAE as @mclow.lists suggested in his comment. Marshall, do you care, and if so, why? https://reviews.llvm.org/D41748 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
BillyONeal added a comment. > I hate your compiler. Seems like a valid warning to me :) Changed predicate to one that adds 10 to each input. https://reviews.llvm.org/D41748 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
BillyONeal updated this revision to Diff 128836. BillyONeal marked 3 inline comments as done. BillyONeal added a comment. Also change predicate from identity to add_ten. https://reviews.llvm.org/D41748 Files: test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp Index: test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp === --- test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp +++ 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 @@ 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 @@ 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 @@ { 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 + trian
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
mclow.lists added a comment. > The use of iota targeting vector with an int parameter > triggers warnings on MSVC++ assigning an into a unsigned char& I hate your compiler. Other than that (and the bit about identity), this looks fine to me. Comment at: test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp:31 -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); } -}; +const auto identity = [](auto&& x) { return std::forward(x); }; CaseyCarter wrote: > Pre-existing: the identity transformation is an extremely poor choice for > these `transform_foo` tests since failure to apply the transformation exactly > once to each element does not affect the result of the algorithm. I think I'd rather have this. It's constexpr and noexcept, unlike the lambda. struct identity { template constexpr auto operator()(T&& x) const noexcept(noexcept(std::forward(x))) -> decltype (std::forward(x)) { return std::forward(x); } }; Comment at: test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp:31 -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); } -}; +const auto identity = [](auto&& x) { return std::forward(x); }; mclow.lists wrote: > CaseyCarter wrote: > > Pre-existing: the identity transformation is an extremely poor choice for > > these `transform_foo` tests since failure to apply the transformation > > exactly once to each element does not affect the result of the algorithm. > I think I'd rather have this. It's constexpr and noexcept, unlike the lambda. > > struct identity { > template > constexpr auto operator()(T&& x) const > noexcept(noexcept(std::forward(x))) > -> decltype (std::forward(x)) > { return std::forward(x); } > }; > I agree about the choice of `identity` as a transform. https://reviews.llvm.org/D41748 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
CaseyCarter added inline comments. Comment at: test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp:31 -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); } -}; +const auto identity = [](auto&& x) { return std::forward(x); }; Pre-existing: the identity transformation is an extremely poor choice for these `transform_foo` tests since failure to apply the transformation exactly once to each element does not affect the result of the algorithm. https://reviews.llvm.org/D41748 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
BillyONeal created this revision. BillyONeal added reviewers: mclow.lists, EricWF. - 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) https://reviews.llvm.org/D41748 Files: test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp Index: test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp === --- test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp +++ test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp @@ -20,26 +20,15 @@ #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); } -}; +const auto identity = [](auto&& x) { return std::forward(x); }; template void @@ -82,12 +71,12 @@ 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<>(), 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<>(), 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<>(), 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<>(), std::negate<>(), 2, pResN2, pResN2 + i); test(Iter(ia), Iter(ia + i), std::multiplies<>(), std::negate<>(), 2, mResN2, mResN2 + i); } @@ -101,39 +90,39 @@ { 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<>(), identity, 50); for (size_t i = 0; i < v.size(); ++i) assert(v[i] == 50 + (int) (i + 1) * 3); } { 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<>(), identity, 30); for (size_t i = 0; i < v.size(); ++i) assert(v[i] == 30 + triangle(i)); } { 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<>(), identity, 40); for (size_t i = 0; i < v.size(); ++i) assert(v[i] == 40 + triangle(i + 1)); } { 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<>(), identity, 1); assert(res.empty()); } // Make sure th