From 1d3085a6bfda9d49a3c33db1a6413fbc55c196bf Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Fri, 14 Jun 2024 18:56:14 +0200 Subject: [PATCH] Implement thrust::all_of/any_of via thrust::count_if Related to: #720 --- thrust/thrust/system/detail/generic/logical.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/thrust/thrust/system/detail/generic/logical.h b/thrust/thrust/system/detail/generic/logical.h index 05f0952f6f7..ddd3db8feca 100644 --- a/thrust/thrust/system/detail/generic/logical.h +++ b/thrust/thrust/system/detail/generic/logical.h @@ -25,10 +25,8 @@ #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header -#include -#include +#include #include -#include THRUST_NAMESPACE_BEGIN namespace system @@ -42,14 +40,16 @@ template _CCCL_HOST_DEVICE bool all_of(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred) { - return thrust::find_if(exec, first, last, thrust::detail::not1(pred)) == last; + // TODO(bgruber): we could implement this even better using an early exit + return thrust::count_if(exec, first, last, thrust::detail::not1(pred)) == 0; } template _CCCL_HOST_DEVICE bool any_of(thrust::execution_policy& exec, InputIterator first, InputIterator last, Predicate pred) { - return thrust::find_if(exec, first, last, pred) != last; + // TODO(bgruber): we could implement this even better using an early exit + return thrust::count_if(exec, first, last, pred) > 0; } template