From 989cad247609bc2f2ae4cd16f4e90047a7604b60 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Thu, 4 Jul 2019 20:00:39 +0000 Subject: [pstl] Use utilities from instead of reinventing the wheel llvm-svn: 365158 --- pstl/include/pstl/internal/algorithm_impl.h | 22 +++++----- pstl/include/pstl/internal/glue_algorithm_impl.h | 45 +++++++++------------ pstl/include/pstl/internal/utils.h | 47 ---------------------- .../alg.partitions/partition_copy.pass.cpp | 10 ++--- .../alg.set.operations/includes.pass.cpp | 8 ++-- .../alg.sorting/alg.set.operations/set.pass.cpp | 10 ++--- 6 files changed, 42 insertions(+), 100 deletions(-) (limited to 'pstl') diff --git a/pstl/include/pstl/internal/algorithm_impl.h b/pstl/include/pstl/internal/algorithm_impl.h index 5956e2e..ae0657d 100644 --- a/pstl/include/pstl/internal/algorithm_impl.h +++ b/pstl/include/pstl/internal/algorithm_impl.h @@ -401,9 +401,7 @@ __brick_equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _ if (__last1 - __first1 != __last2 - __first2) return false; - return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, - __internal::__not_pred<_BinaryPredicate>(__p)) - .first == __last1; + return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, std::not_fn(__p)).first == __last1; } template (__p)) - .first == __last1; + return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, std::not_fn(__p)).first == __last1; } template (__global_last - __first) >= __count) && - !__internal::__brick_any_of(__first + 1, __first + __count, - __not_pred(__unary_pred), __is_vector)) + !__internal::__brick_any_of(__first + 1, __first + __count, std::not_fn(__unary_pred), __is_vector)) { return __first; } @@ -1762,7 +1758,7 @@ __pattern_is_partitioned(_ExecutionPolicy&& __exec, _ForwardIterator __first, _F { // find first element that don't satisfy pred _ForwardIterator __x = - __internal::__brick_find_if(__i + 1, __j, __not_pred<_UnaryPredicate>(__pred), __is_vector); + __internal::__brick_find_if(__i + 1, __j, std::not_fn(__pred), __is_vector); if (__x != __j) { // find first element after "x" that satisfy pred @@ -3441,14 +3437,14 @@ __pattern_minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _F std::forward<_ExecutionPolicy>(__exec), __first + 1, __last, std::make_pair(__first, __first), [=](_ForwardIterator __begin, _ForwardIterator __end, _Result __init) -> _Result { const _Result __subresult = __internal::__brick_minmax_element(__begin, __end, __comp, __is_vector); - return std::make_pair(__internal::__cmp_iterators_by_values(__subresult.first, __init.first, __comp), - __internal::__cmp_iterators_by_values(__init.second, __subresult.second, - __not_pred<_Compare>(__comp))); + return std::make_pair( + __internal::__cmp_iterators_by_values(__subresult.first, __init.first, __comp), + __internal::__cmp_iterators_by_values(__init.second, __subresult.second, std::not_fn(__comp))); }, [=](_Result __p1, _Result __p2) -> _Result { return std::make_pair( __internal::__cmp_iterators_by_values(__p1.first, __p2.first, __comp), - __internal::__cmp_iterators_by_values(__p2.second, __p1.second, __not_pred<_Compare>(__comp))); + __internal::__cmp_iterators_by_values(__p2.second, __p1.second, std::not_fn(__comp))); }); }); } @@ -3485,7 +3481,7 @@ __brick_mismatch(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _Forward _ForwardIterator2 __last2, _Predicate __pred, /* __is_vector = */ std::true_type) noexcept { auto __n = std::min(__last1 - __first1, __last2 - __first2); - return __unseq_backend::__simd_first(__first1, __n, __first2, __not_pred<_Predicate>(__pred)); + return __unseq_backend::__simd_first(__first1, __n, __first2, std::not_fn(__pred)); } template diff --git a/pstl/include/pstl/internal/glue_algorithm_impl.h b/pstl/include/pstl/internal/glue_algorithm_impl.h index 2c4f432..81a0d4d 100644 --- a/pstl/include/pstl/internal/glue_algorithm_impl.h +++ b/pstl/include/pstl/internal/glue_algorithm_impl.h @@ -43,8 +43,7 @@ template __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> all_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) { - return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, - __pstl::__internal::__not_pred<_Pred>(__pred)); + return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::not_fn(__pred)); } // [alg.none_of] @@ -96,8 +95,7 @@ template __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> find_if_not(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - return std::find_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, - __pstl::__internal::__not_pred<_Predicate>(__pred)); + return std::find_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::not_fn(__pred)); } template @@ -127,7 +125,7 @@ find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 _ForwardIterator2 __s_last) { return std::find_end(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last, - __pstl::__internal::__pstl_equal()); + std::equal_to<>()); } // [alg.find_first_of] @@ -149,7 +147,7 @@ find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIter _ForwardIterator2 __s_first, _ForwardIterator2 __s_last) { return std::find_first_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last, - __pstl::__internal::__pstl_equal()); + std::equal_to<>()); } // [alg.adjacent_find] @@ -226,8 +224,7 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardItera search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first, _ForwardIterator2 __s_last) { - return std::search(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last, - __pstl::__internal::__pstl_equal()); + return std::search(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last, std::equal_to<>()); } template @@ -465,8 +462,7 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardItera remove_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result, _Predicate __pred) { - return std::copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, - __pstl::__internal::__not_pred<_Predicate>(__pred)); + return std::copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, std::not_fn(__pred)); } template @@ -514,7 +510,7 @@ template __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last) { - return std::unique(std::forward<_ExecutionPolicy>(__exec), __first, __last, __pstl::__internal::__pstl_equal()); + return std::unique(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::equal_to<>()); } template @@ -533,7 +529,7 @@ template unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result) { - return std::unique_copy(__exec, __first, __last, __result, __pstl::__internal::__pstl_equal()); + return std::unique_copy(__exec, __first, __last, __result, std::equal_to<>()); } // [alg.reverse] @@ -710,7 +706,7 @@ mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator _ForwardIterator2 __last2) { return std::mismatch(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, - __pstl::__internal::__pstl_equal()); + std::equal_to<>()); } template @@ -740,8 +736,7 @@ template equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { - return std::equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, - __pstl::__internal::__pstl_equal()); + return std::equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, std::equal_to<>()); } template @@ -761,8 +756,7 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, - __pstl::__internal::__pstl_equal()); + return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, std::equal_to<>()); } // [alg.move] @@ -825,7 +819,7 @@ partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardI _RandomAccessIterator __d_first, _RandomAccessIterator __d_last) { return std::partial_sort_copy(std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first, __d_last, - __pstl::__internal::__pstl_less()); + std::less<>()); } // [is.sorted] @@ -891,7 +885,7 @@ merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 _ _ForwardIterator2 __last2, _ForwardIterator __d_first) { return std::merge(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first, - __pstl::__internal::__pstl_less()); + std::less<>()); } template @@ -934,8 +928,7 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { - return std::includes(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, - __pstl::__internal::__pstl_less()); + return std::includes(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, std::less<>()); } // [set.union] @@ -961,7 +954,7 @@ set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterato _ForwardIterator2 __last2, _ForwardIterator __result) { return std::set_union(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, - __pstl::__internal::__pstl_less()); + std::less<>()); } // [set.intersection] @@ -987,7 +980,7 @@ set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forward _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result) { return std::set_intersection(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, - __pstl::__internal::__pstl_less()); + std::less<>()); } // [set.difference] @@ -1013,7 +1006,7 @@ set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIt _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result) { return std::set_difference(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, - __pstl::__internal::__pstl_less()); + std::less<>()); } // [set.symmetric.difference] @@ -1040,7 +1033,7 @@ set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result) { return std::set_symmetric_difference(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, - __result, __pstl::__internal::__pstl_less()); + __result, std::less<>()); } // [is.heap] @@ -1178,7 +1171,7 @@ lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ _ForwardIterator2 __first2, _ForwardIterator2 __last2) { return std::lexicographical_compare(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, - __pstl::__internal::__pstl_less()); + std::less<>()); } } // namespace std diff --git a/pstl/include/pstl/internal/utils.h b/pstl/include/pstl/internal/utils.h index 16e6f4c..0f5b834 100644 --- a/pstl/include/pstl/internal/utils.h +++ b/pstl/include/pstl/internal/utils.h @@ -85,23 +85,6 @@ struct __no_op } }; -//! Logical negation of a predicate -template -class __not_pred -{ - _Pred _M_pred; - - public: - explicit __not_pred(_Pred __pred) : _M_pred(__pred) {} - - template - bool - operator()(_Args&&... __args) - { - return !_M_pred(std::forward<_Args>(__args)...); - } -}; - template class __reorder_pred { @@ -118,36 +101,6 @@ class __reorder_pred } }; -//! "==" comparison. -/** Not called "equal" to avoid (possibly unfounded) concerns about accidental invocation via - argument-dependent name lookup by code expecting to find the usual std::equal. */ -class __pstl_equal -{ - public: - explicit __pstl_equal() {} - - template - bool - operator()(_Xp&& __x, _Yp&& __y) const - { - return std::forward<_Xp>(__x) == std::forward<_Yp>(__y); - } -}; - -//! "<" comparison. -class __pstl_less -{ - public: - explicit __pstl_less() {} - - template - bool - operator()(_Xp&& __x, _Yp&& __y) const - { - return std::forward<_Xp>(__x) < std::forward<_Yp>(__y); - } -}; - //! Like a polymorphic lambda for pred(...,value) template class __equal_value_by_pred diff --git a/pstl/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp b/pstl/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp index b1f6cd9..a391ba8 100644 --- a/pstl/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp +++ b/pstl/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_copy.pass.cpp @@ -12,9 +12,10 @@ // Tests for stable_partition and partition_copy #include "support/pstl_test_config.h" -#include #include #include +#include +#include #include #include "support/utils.h" @@ -26,16 +27,15 @@ struct test_partition_copy template void - operator()(Policy&& exec, InputIterator first, InputIterator last, OutputIterator true_first, - OutputIterator, OutputIterator2 false_first, OutputIterator2, UnaryOp unary_op) + operator()(Policy&& exec, InputIterator first, InputIterator last, OutputIterator true_first, OutputIterator, + OutputIterator2 false_first, OutputIterator2, UnaryOp unary_op) { auto actual_ret = std::partition_copy(exec, first, last, true_first, false_first, unary_op); EXPECT_TRUE(std::distance(true_first, actual_ret.first) == std::count_if(first, last, unary_op), "partition_copy has wrong effect from true sequence"); - EXPECT_TRUE(std::distance(false_first, actual_ret.second) == - std::count_if(first, last, __pstl::__internal::__not_pred(unary_op)), + EXPECT_TRUE(std::distance(false_first, actual_ret.second) == std::count_if(first, last, std::not_fn(unary_op)), "partition_copy has wrong effect from false sequence"); } diff --git a/pstl/test/std/algorithms/alg.sorting/alg.set.operations/includes.pass.cpp b/pstl/test/std/algorithms/alg.sorting/alg.set.operations/includes.pass.cpp index 8851cec..2f4a72f 100644 --- a/pstl/test/std/algorithms/alg.sorting/alg.set.operations/includes.pass.cpp +++ b/pstl/test/std/algorithms/alg.sorting/alg.set.operations/includes.pass.cpp @@ -11,9 +11,10 @@ #include "support/pstl_test_config.h" +#include #include #include -#include +#include #include "support/utils.h" @@ -57,8 +58,7 @@ struct test_one_policy template typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, - Compare) + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) { } }; @@ -98,7 +98,7 @@ int32_t main() { - test_includes(__pstl::__internal::__pstl_less()); + test_includes(std::less<>()); test_includes, Num>([](const Num& x, const Num& y) { return x < y; }); std::cout << done() << std::endl; diff --git a/pstl/test/std/algorithms/alg.sorting/alg.set.operations/set.pass.cpp b/pstl/test/std/algorithms/alg.sorting/alg.set.operations/set.pass.cpp index b54a6b6..35ab452 100644 --- a/pstl/test/std/algorithms/alg.sorting/alg.set.operations/set.pass.cpp +++ b/pstl/test/std/algorithms/alg.sorting/alg.set.operations/set.pass.cpp @@ -11,10 +11,11 @@ #include "support/pstl_test_config.h" -#include +#include #include +#include #include -#include +#include #include "support/utils.h" @@ -97,8 +98,7 @@ struct test_one_policy template typename std::enable_if::value, void>::type - operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, - Compare) + operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare) { } }; @@ -151,7 +151,7 @@ int32_t main() { - test_set(__pstl::__internal::__pstl_less()); + test_set(std::less<>()); test_set, Num>([](const Num& x, const Num& y) { return x < y; }); test_algo_basic_double(run_for_rnd_fw>()); -- cgit v1.1