diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -642,6 +642,7 @@ __type_traits/is_empty.h __type_traits/is_enum.h __type_traits/is_equality_comparable.h + __type_traits/is_execution_policy.h __type_traits/is_final.h __type_traits/is_floating_point.h __type_traits/is_function.h @@ -742,6 +743,7 @@ __utility/priority_tag.h __utility/rel_ops.h __utility/swap.h + __utility/terminate_on_exception.h __utility/to_underlying.h __utility/unreachable.h __variant/monostate.h diff --git a/libcxx/include/__algorithm/all_of.h b/libcxx/include/__algorithm/all_of.h --- a/libcxx/include/__algorithm/all_of.h +++ b/libcxx/include/__algorithm/all_of.h @@ -10,7 +10,9 @@ #ifndef _LIBCPP___ALGORITHM_ALL_OF_H #define _LIBCPP___ALGORITHM_ALL_OF_H +#include <__algorithm/any_of.h> #include <__config> +#include <__functional/not_fn.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -19,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +_LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) @@ -27,6 +29,19 @@ return true; } +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 + +template >, int> = 0> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool +all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) { + return !std::any_of(__policy, __first, __last, std::not_fn(__pred)); +} + +#endif // defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_ALL_OF_H diff --git a/libcxx/include/__algorithm/any_of.h b/libcxx/include/__algorithm/any_of.h --- a/libcxx/include/__algorithm/any_of.h +++ b/libcxx/include/__algorithm/any_of.h @@ -10,7 +10,14 @@ #ifndef _LIBCPP___ALGORITHM_ANY_OF_H #define _LIBCPP___ALGORITHM_ANY_OF_H +#include <__algorithm/for_each.h> #include <__config> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_execution_policy.h> +#include <__utility/terminate_on_exception.h> +#include +#include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -27,6 +34,36 @@ return false; } +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 + +template >, int> = 0> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool +any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { + if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> && + __is_cpp17_random_access_iterator<_ForwardIterator>::value) { + return std::__terminate_on_exception([&] { + return __pstl::__internal::__parallel_or( + {}, + __policy, + __first, + __last, + [&__policy, &__pred](_ForwardIterator __brick_first, _ForwardIterator __brick_last) { + return std::any_of(std::__remove_parallel_policy(__policy), __brick_first, __brick_last, __pred); + }); + }); + } else if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> && + __is_cpp17_random_access_iterator<_ForwardIterator>::value) { + return __pstl::__unseq_backend::__simd_or(__first, __last - __first, __pred); + } else { + return std::any_of(__first, __last, __pred); + } +} + +#endif // defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_ANY_OF_H diff --git a/libcxx/include/__algorithm/none_of.h b/libcxx/include/__algorithm/none_of.h --- a/libcxx/include/__algorithm/none_of.h +++ b/libcxx/include/__algorithm/none_of.h @@ -10,6 +10,7 @@ #ifndef _LIBCPP___ALGORITHM_NONE_OF_H #define _LIBCPP___ALGORITHM_NONE_OF_H +#include <__algorithm/any_of.h> #include <__config> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -27,6 +28,19 @@ return true; } +#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 + +template >, int> = 0> +_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool +none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) { + return !std::any_of(__policy, __first, __last, __pred); +} + +#endif // defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_NONE_OF_H diff --git a/libcxx/include/__type_traits/is_execution_policy.h b/libcxx/include/__type_traits/is_execution_policy.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__type_traits/is_execution_policy.h @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TYPE_TRAITS_IS_EQUAILITY_COMPARABLE_H +#define _LIBCPP___TYPE_TRAITS_IS_EQUAILITY_COMPARABLE_H + +#include <__config> +#include <__type_traits/remove_cvref.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +inline constexpr bool is_execution_policy_v = false; + +template +inline constexpr bool __is_unsequenced_execution_policy_impl = false; + +template +inline constexpr bool __is_unsequenced_execution_policy_v = __is_unsequenced_execution_policy_impl>; + +template +inline constexpr bool __is_parallel_execution_policy_impl = false; + +template +inline constexpr bool __is_parallel_execution_policy_v = __is_parallel_execution_policy_impl>; + +template +auto&& __remove_parallel_policy(_ExecutionPolicy&&); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___TYPE_TRAITS_IS_EQUAILITY_COMPARABLE_H diff --git a/libcxx/include/__algorithm/any_of.h b/libcxx/include/__utility/terminate_on_exception.h copy from libcxx/include/__algorithm/any_of.h copy to libcxx/include/__utility/terminate_on_exception.h --- a/libcxx/include/__algorithm/any_of.h +++ b/libcxx/include/__utility/terminate_on_exception.h @@ -1,4 +1,3 @@ -// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. @@ -7,10 +6,11 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___ALGORITHM_ANY_OF_H -#define _LIBCPP___ALGORITHM_ANY_OF_H +#ifndef _LIBCPP___UTILITY_TERMINATE_ON_EXCEPTION_H +#define _LIBCPP___UTILITY_TERMINATE_ON_EXCEPTION_H #include <__config> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -18,15 +18,19 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (__pred(*__first)) - return true; - return false; +template +_LIBCPP_HIDE_FROM_ABI auto __terminate_on_exception(_Func __func) { +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif + return __func(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } catch (...) { + std::terminate(); + } +#endif } _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___ALGORITHM_ANY_OF_H +#endif // _LIBCPP___UTILITY_TERMINATE_ON_EXCEPTION_H diff --git a/libcxx/include/execution b/libcxx/include/execution --- a/libcxx/include/execution +++ b/libcxx/include/execution @@ -13,6 +13,9 @@ #include <__assert> // all public C++ headers provide the assertion handler #include <__config> #include <__type_traits/integral_constant.h> +#include <__type_traits/is_execution_policy.h> +#include <__type_traits/is_same.h> +#include <__type_traits/remove_cvref.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -52,6 +55,15 @@ constexpr parallel_unsequenced_policy par_unseq{__disable_user_instantiations_tag{}}; +// TODO: Do we want to make this a supported extension in C++17? +struct __unsequenced_policy { + constexpr explicit __unsequenced_policy(__disable_user_instantiations_tag) {} + __unsequenced_policy(const __unsequenced_policy&) = delete; + __unsequenced_policy& operator=(const __unsequenced_policy&) = delete; +}; + +constexpr __unsequenced_policy __unseq{__disable_user_instantiations_tag{}}; + # if _LIBCPP_STD_VER >= 20 struct unsequenced_policy { @@ -66,9 +78,6 @@ } // namespace execution -template -inline constexpr bool is_execution_policy_v = false; - template <> inline constexpr bool is_execution_policy_v = true; @@ -78,14 +87,43 @@ template <> inline constexpr bool is_execution_policy_v = true; +template <> +inline constexpr bool is_execution_policy_v = true; + +template <> +inline constexpr bool __is_parallel_execution_policy_impl = true; + +template <> +inline constexpr bool __is_parallel_execution_policy_impl = true; + +template <> +inline constexpr bool __is_unsequenced_execution_policy_impl = true; + +template <> +inline constexpr bool __is_unsequenced_execution_policy_impl = true; + # if _LIBCPP_STD_VER >= 20 template <> inline constexpr bool is_execution_policy_v = true; + +template <> +inline constexpr bool __is_unsequenced_execution_policy_impl = true; + # endif template struct is_execution_policy : bool_constant> {}; +template +auto&& __remove_parallel_policy(_ExecutionPolicy&&) { + using _ExecPol = remove_cvref_t<_ExecutionPolicy>; + if constexpr (is_same_v<_ExecPol, execution::parallel_policy>) { + return execution::seq; + } else if constexpr (is_same_v<_ExecPol, execution::parallel_unsequenced_policy>) { + return execution::__unseq; + } +} + _LIBCPP_END_NAMESPACE_STD #endif // defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -1498,6 +1498,7 @@ private header "__type_traits/is_equality_comparable.h" export integral_constant } + module is_execution_policy { private header "__type_traits/is_execution_policy.h" } module is_final { private header "__type_traits/is_final.h" } module is_floating_point { private header "__type_traits/is_floating_point.h" } module is_function { private header "__type_traits/is_function.h" } diff --git a/libcxx/include/pstl/internal/algorithm_fwd.h b/libcxx/include/pstl/internal/algorithm_fwd.h --- a/libcxx/include/pstl/internal/algorithm_fwd.h +++ b/libcxx/include/pstl/internal/algorithm_fwd.h @@ -21,29 +21,6 @@ namespace __pstl { namespace __internal { -//------------------------------------------------------------------------ -// any_of -//------------------------------------------------------------------------ - -template -bool __brick_any_of(const _ForwardIterator, - const _ForwardIterator, - _Pred, - /*__is_vector=*/std::false_type) noexcept; - -template -bool __brick_any_of(const _RandomAccessIterator, - const _RandomAccessIterator, - _Pred, - /*__is_vector=*/std::true_type) noexcept; - -template -bool __pattern_any_of(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Pred) noexcept; - -template -bool __pattern_any_of( - __parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Pred); - //------------------------------------------------------------------------ // walk1 (pseudo) // diff --git a/libcxx/include/pstl/internal/algorithm_impl.h b/libcxx/include/pstl/internal/algorithm_impl.h --- a/libcxx/include/pstl/internal/algorithm_impl.h +++ b/libcxx/include/pstl/internal/algorithm_impl.h @@ -29,52 +29,6 @@ namespace __pstl { namespace __internal { -//------------------------------------------------------------------------ -// any_of -//------------------------------------------------------------------------ - -template -bool __brick_any_of(const _ForwardIterator __first, - const _ForwardIterator __last, - _Pred __pred, - /*__is_vector=*/std::false_type) noexcept { - return std::any_of(__first, __last, __pred); -}; - -template -bool __brick_any_of(const _RandomAccessIterator __first, - const _RandomAccessIterator __last, - _Pred __pred, - /*__is_vector=*/std::true_type) noexcept { - return __unseq_backend::__simd_or(__first, __last - __first, __pred); -}; - -template -bool __pattern_any_of( - _Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) noexcept { - return __internal::__brick_any_of(__first, __last, __pred, typename _Tag::__is_vector{}); -} - -template -bool __pattern_any_of(__parallel_tag<_IsVector> __tag, - _ExecutionPolicy&& __exec, - _RandomAccessIterator __first, - _RandomAccessIterator __last, - _Pred __pred) { - using __backend_tag = typename decltype(__tag)::__backend_tag; - - return __internal::__except_handler([&]() { - return __internal::__parallel_or( - __backend_tag{}, - std::forward<_ExecutionPolicy>(__exec), - __first, - __last, - [__pred](_RandomAccessIterator __i, _RandomAccessIterator __j) { - return __internal::__brick_any_of(__i, __j, __pred, _IsVector{}); - }); - }); -} - // [alg.foreach] // for_each_n with no policy diff --git a/libcxx/include/pstl/internal/glue_algorithm_defs.h b/libcxx/include/pstl/internal/glue_algorithm_defs.h --- a/libcxx/include/pstl/internal/glue_algorithm_defs.h +++ b/libcxx/include/pstl/internal/glue_algorithm_defs.h @@ -20,24 +20,6 @@ namespace std { -// [alg.any_of] - -template -__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> -any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred); - -// [alg.all_of] - -template -__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> -all_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred); - -// [alg.none_of] - -template -__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> -none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred); - // [alg.foreach] template diff --git a/libcxx/include/pstl/internal/glue_algorithm_impl.h b/libcxx/include/pstl/internal/glue_algorithm_impl.h --- a/libcxx/include/pstl/internal/glue_algorithm_impl.h +++ b/libcxx/include/pstl/internal/glue_algorithm_impl.h @@ -25,33 +25,6 @@ namespace std { -// [alg.any_of] - -template -__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> -any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first); - - return __pstl::__internal::__pattern_any_of( - __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __pred); -} - -// [alg.all_of] - -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, std::not_fn(__pred)); -} - -// [alg.none_of] - -template -__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> -none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { - return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, __pred); -} - // [alg.foreach] template diff --git a/libcxx/include/pstl/internal/parallel_backend_serial.h b/libcxx/include/pstl/internal/parallel_backend_serial.h --- a/libcxx/include/pstl/internal/parallel_backend_serial.h +++ b/libcxx/include/pstl/internal/parallel_backend_serial.h @@ -10,11 +10,9 @@ #ifndef _PSTL_PARALLEL_BACKEND_SERIAL_H #define _PSTL_PARALLEL_BACKEND_SERIAL_H -#include -#include -#include -#include -#include +#include <__memory/allocator.h> +#include <__utility/forward.h> +#include #include "pstl_config.h" diff --git a/libcxx/include/pstl/internal/parallel_impl.h b/libcxx/include/pstl/internal/parallel_impl.h --- a/libcxx/include/pstl/internal/parallel_impl.h +++ b/libcxx/include/pstl/internal/parallel_impl.h @@ -13,6 +13,7 @@ #include "pstl_config.h" #include +#include // This header defines the minimum set of parallel routines required to support Parallel STL, // implemented on top of Intel(R) Threading Building Blocks (Intel(R) TBB) library @@ -65,10 +66,8 @@ // parallel_or //------------------------------------------------------------------------ //! Return true if brick f[i,j) returns true for some subrange [i,j) of [first,last) -template -bool -__parallel_or(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f) -{ +template +bool __parallel_or(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f) { std::atomic __found(false); __par_backend::__parallel_for(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, [__f, &__found](_Index __i, _Index __j) diff --git a/libcxx/include/pstl/internal/unseq_backend_simd.h b/libcxx/include/pstl/internal/unseq_backend_simd.h --- a/libcxx/include/pstl/internal/unseq_backend_simd.h +++ b/libcxx/include/pstl/internal/unseq_backend_simd.h @@ -10,6 +10,7 @@ #ifndef _PSTL_UNSEQ_BACKEND_SIMD_H #define _PSTL_UNSEQ_BACKEND_SIMD_H +#include <__functional/operations.h> #include #include "pstl_config.h" diff --git a/libcxx/test/libcxx/private_headers.verify.cpp b/libcxx/test/libcxx/private_headers.verify.cpp --- a/libcxx/test/libcxx/private_headers.verify.cpp +++ b/libcxx/test/libcxx/private_headers.verify.cpp @@ -656,6 +656,7 @@ #include <__type_traits/is_empty.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_empty.h'}} #include <__type_traits/is_enum.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_enum.h'}} #include <__type_traits/is_equality_comparable.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_equality_comparable.h'}} +#include <__type_traits/is_execution_policy.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_execution_policy.h'}} #include <__type_traits/is_final.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_final.h'}} #include <__type_traits/is_floating_point.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_floating_point.h'}} #include <__type_traits/is_function.h> // expected-error@*:* {{use of private header from outside its module: '__type_traits/is_function.h'}} @@ -755,6 +756,7 @@ #include <__utility/priority_tag.h> // expected-error@*:* {{use of private header from outside its module: '__utility/priority_tag.h'}} #include <__utility/rel_ops.h> // expected-error@*:* {{use of private header from outside its module: '__utility/rel_ops.h'}} #include <__utility/swap.h> // expected-error@*:* {{use of private header from outside its module: '__utility/swap.h'}} +#include <__utility/terminate_on_exception.h> // expected-error@*:* {{use of private header from outside its module: '__utility/terminate_on_exception.h'}} #include <__utility/to_underlying.h> // expected-error@*:* {{use of private header from outside its module: '__utility/to_underlying.h'}} #include <__utility/unreachable.h> // expected-error@*:* {{use of private header from outside its module: '__utility/unreachable.h'}} #include <__variant/monostate.h> // expected-error@*:* {{use of private header from outside its module: '__variant/monostate.h'}} diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/pstl.all_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/pstl.all_of.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.all_of/pstl.all_of.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: with-pstl + +// + +// template +// bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, +// Predicate pred); + +#include +#include + +#include "test_macros.h" +#include "test_execution_policies.h" + +struct Test { + template + void operator()(Policy&& policy) { + int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; + // simple test + assert(std::all_of(policy, std::begin(a), std::end(a), [](int i) { return i < 9; })); + assert(!std::all_of(policy, std::begin(a), std::end(a), [](int i) { return i < 8; })); + + // check that an empty range works + assert(std::all_of(policy, std::begin(a), std::begin(a), [](int) { return false; })); + + // check that false is returned if no element satisfies the condition + assert(!std::all_of(policy, std::begin(a), std::end(a), [](int i) { return i == 9; })); + + // check that false is returned if only one elements satisfies the condition + assert(!std::all_of(policy, std::begin(a), std::end(a), [](int i) { return i == 1; })); + } +}; + +int main(int, char**) { + test_execution_policies(Test{}); + +#ifndef TEST_HAS_NO_EXCEPTIONS + std::set_terminate(terminate_successful); + int a[] = {1, 2}; + (void)std::all_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); + assert(false); +#endif + + return 0; +} diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/pstl.any_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/pstl.any_of.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.any_of/pstl.any_of.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: with-pstl + +// + +// template +// bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, +// Predicate pred); + +#include +#include + +#include "test_macros.h" +#include "test_execution_policies.h" + +struct Test { + template + void operator()(Policy&& policy) { + int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; + // simple test + assert(std::any_of(policy, std::begin(a), std::end(a), [](int i) { return i < 9; })); + assert(!std::any_of(policy, std::begin(a), std::end(a), [](int i) { return i > 8; })); + + // check that an empty range works + assert(!std::any_of(policy, std::begin(a), std::begin(a), [](int) { return false; })); + + // check that false is returned if no element satisfies the condition + assert(!std::any_of(policy, std::begin(a), std::end(a), [](int i) { return i == 9; })); + + // check that true is returned if only one elements satisfies the condition + assert(std::any_of(policy, std::begin(a), std::end(a), [](int i) { return i == 1; })); + } +}; + +int main(int, char**) { + test_execution_policies(Test{}); + +#ifndef TEST_HAS_NO_EXCEPTIONS + std::set_terminate(terminate_successful); + int a[] = {1, 2}; + (void)std::any_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); + assert(false); +#endif + + return 0; +} diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// REQUIRES: with-pstl + +// + +// template +// bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, +// Predicate pred); + +#include +#include + +#include "test_macros.h" +#include "test_execution_policies.h" + +struct Test { + template + void operator()(Policy&& policy) { + int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; + // simple test + assert(std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i > 9; })); + assert(!std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i >= 8; })); + + // check that an empty range works + assert(std::none_of(policy, std::begin(a), std::begin(a), [](int) { return false; })); + + // check that true is returned if no element satisfies the condition + assert(std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i == 9; })); + + // check that false is returned if only one elements satisfies the condition + assert(!std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i == 1; })); + } +}; + +int main(int, char**) { + test_execution_policies(Test{}); + +#ifndef TEST_HAS_NO_EXCEPTIONS + std::set_terminate(terminate_successful); + int a[] = {1, 2}; + (void)std::none_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); + assert(false); +#endif + + return 0; +} diff --git a/libcxx/test/support/test_execution_policies.h b/libcxx/test/support/test_execution_policies.h new file mode 100644 --- /dev/null +++ b/libcxx/test/support/test_execution_policies.h @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_SUPPORT_TEST_EXECUTION_POLICIES +#define TEST_SUPPORT_TEST_EXECUTION_POLICIES + +#include +#include + +#include "test_macros.h" + +template +bool test_execution_policies(Functor func) { + func(std::execution::seq); +#if TEST_STD_VER >= 20 + func(std::execution::unseq); +#endif + func(std::execution::par); + func(std::execution::par_unseq); + + return true; +} + +[[noreturn]] inline void terminate_successful() { std::exit(0); } + +#endif // TEST_SUPPORT_TEST_EXECUTION_POLICIES diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt --- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt +++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL) set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC) -find_package(Clang 16...17) +find_package(Clang 16) set(SOURCES abi_tag_on_virtual.cpp