diff options
author | Billy Robert O'Neal III <bion@microsoft.com> | 2018-01-05 01:31:47 +0000 |
---|---|---|
committer | Billy Robert O'Neal III <bion@microsoft.com> | 2018-01-05 01:31:47 +0000 |
commit | 61d97da4f417b3a9d94b8ea0939e414d177ff2df (patch) | |
tree | 9540fbb7260faa147ad83f01c4a5d2913aeffa01 | |
parent | 6c63a6c9a133f652fd406f806d8dfa60445e48e1 (diff) | |
download | llvm-61d97da4f417b3a9d94b8ea0939e414d177ff2df.zip llvm-61d97da4f417b3a9d94b8ea0939e414d177ff2df.tar.gz llvm-61d97da4f417b3a9d94b8ea0939e414d177ff2df.tar.bz2 |
Fix nonstandard bits in transform_reduce_iter_iter_init_bop_uop.
* _VSTD should be std.
* <utility> is needed for forward.
* unary_function is no longer standard (and unnecessary for this, a C++17-only test)
llvm-svn: 321847
-rw-r--r-- | libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp | 70 |
1 files changed, 27 insertions, 43 deletions
diff --git a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp index 418c57f..98c58f9 100644 --- a/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp @@ -18,40 +18,24 @@ #include <numeric> #include <cassert> +#include <utility> #include "test_iterators.h" -template <class T = void> -struct identity : std::unary_function<T, T> -{ - constexpr const T& operator()(const T& x) const { return x;} -}; - -template <> -struct identity<void> +struct identity { template <class T> - constexpr auto operator()(T&& x) const - _NOEXCEPT_(noexcept(_VSTD::forward<T>(x))) - -> decltype (_VSTD::forward<T>(x)) - { return _VSTD::forward<T>(x); } + constexpr decltype(auto) operator()(T&& x) const { + return std::forward<T>(x); + } }; - -template <class T = void> struct twice { - constexpr const T operator()(const T& x) const noexcept { return 2 * x; } -}; - -template <> -struct twice<void> -{ template <class T> - constexpr auto operator()(const T& x) const - _NOEXCEPT_(noexcept(2 * x)) - -> decltype (2 * x) - { return 2 * x; } + constexpr auto operator()(const T& x) const { + return 2 * x; + } }; template <class Iter1, class T, class BOp, class UOp> @@ -70,23 +54,23 @@ test() int ia[] = {1, 2, 3, 4, 5, 6}; unsigned sa = sizeof(ia) / sizeof(ia[0]); - test(Iter(ia), Iter(ia), 0, std::plus<>(), identity<>(), 0); - test(Iter(ia), Iter(ia), 1, std::multiplies<>(), identity<>(), 1); - test(Iter(ia), Iter(ia+1), 0, std::multiplies<>(), identity<>(), 0); - test(Iter(ia), Iter(ia+1), 2, std::plus<>(), identity<>(), 3); - test(Iter(ia), Iter(ia+2), 0, std::plus<>(), identity<>(), 3); - test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), identity<>(), 6); - test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), identity<>(), 2880); - test(Iter(ia), Iter(ia+sa), 4, std::plus<>(), identity<>(), 25); - - test(Iter(ia), Iter(ia), 0, std::plus<>(), twice<>(), 0); - test(Iter(ia), Iter(ia), 1, std::multiplies<>(), twice<>(), 1); - test(Iter(ia), Iter(ia+1), 0, std::multiplies<>(), twice<>(), 0); - test(Iter(ia), Iter(ia+1), 2, std::plus<>(), twice<>(), 4); - test(Iter(ia), Iter(ia+2), 0, std::plus<>(), twice<>(), 6); - test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), twice<>(), 24); - test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), twice<>(), 184320); // 64 * 2880 - test(Iter(ia), Iter(ia+sa), 4, std::plus<>(), twice<>(), 46); + test(Iter(ia), Iter(ia), 0, std::plus<>(), identity(), 0); + test(Iter(ia), Iter(ia), 1, std::multiplies<>(), identity(), 1); + test(Iter(ia), Iter(ia+1), 0, std::multiplies<>(), identity(), 0); + test(Iter(ia), Iter(ia+1), 2, std::plus<>(), identity(), 3); + test(Iter(ia), Iter(ia+2), 0, std::plus<>(), identity(), 3); + test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), identity(), 6); + test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), identity(), 2880); + test(Iter(ia), Iter(ia+sa), 4, std::plus<>(), identity(), 25); + + test(Iter(ia), Iter(ia), 0, std::plus<>(), twice(), 0); + test(Iter(ia), Iter(ia), 1, std::multiplies<>(), twice(), 1); + test(Iter(ia), Iter(ia+1), 0, std::multiplies<>(), twice(), 0); + test(Iter(ia), Iter(ia+1), 2, std::plus<>(), twice(), 4); + test(Iter(ia), Iter(ia+2), 0, std::plus<>(), twice(), 6); + test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), twice(), 24); + test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), twice(), 184320); // 64 * 2880 + test(Iter(ia), Iter(ia+sa), 4, std::plus<>(), twice(), 46); } template <typename T, typename Init> @@ -94,7 +78,7 @@ void test_return_type() { T *p = nullptr; static_assert( std::is_same_v<Init, - decltype(std::transform_reduce(p, p, Init{}, std::plus<>(), identity<>()))> ); + decltype(std::transform_reduce(p, p, Init{}, std::plus<>(), identity()))> ); } int main() @@ -118,7 +102,7 @@ int main() // Make sure the math is done using the correct type { auto v = {1, 2, 3, 4, 5, 6}; - unsigned res = std::transform_reduce(v.begin(), v.end(), 1U, std::multiplies<>(), twice<>()); + unsigned res = std::transform_reduce(v.begin(), v.end(), 1U, std::multiplies<>(), twice()); assert(res == 46080); // 6! * 64 will not fit into a char } } |