| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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_EXECUTION_POLICY_H | ||
| #define _LIBCPP___TYPE_TRAITS_IS_EXECUTION_POLICY_H | ||
|
|
||
| #include <__config> | ||
| #include <__type_traits/remove_cvref.h> | ||
|
|
||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
| # pragma GCC system_header | ||
| #endif | ||
|
|
||
| #if _LIBCPP_STD_VER >= 17 | ||
|
|
||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||
|
|
||
| template <class> | ||
| inline constexpr bool is_execution_policy_v = false; | ||
|
|
||
| template <class> | ||
| inline constexpr bool __is_unsequenced_execution_policy_impl = false; | ||
|
|
||
| template <class _Tp> | ||
| inline constexpr bool __is_unsequenced_execution_policy_v = | ||
| __is_unsequenced_execution_policy_impl<__remove_cvref_t<_Tp>>; | ||
|
|
||
| template <class> | ||
| inline constexpr bool __is_parallel_execution_policy_impl = false; | ||
|
|
||
| template <class _Tp> | ||
| inline constexpr bool __is_parallel_execution_policy_v = __is_parallel_execution_policy_impl<__remove_cvref_t<_Tp>>; | ||
|
|
||
| // Removes the "parallel" part of an execution policy. | ||
| // For example, turns par_unseq into unseq, and par into seq. | ||
| template <class _ExecutionPolicy> | ||
| const auto& __remove_parallel_policy(_ExecutionPolicy&&); | ||
|
|
||
| _LIBCPP_END_NAMESPACE_STD | ||
|
|
||
| #endif // _LIBCPP_STD_VER >= 17 | ||
|
|
||
| #endif // _LIBCPP___TYPE_TRAITS_IS_EXECUTION_POLICY_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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___UTILITY_TERMINATE_ON_EXCEPTION_H | ||
| #define _LIBCPP___UTILITY_TERMINATE_ON_EXCEPTION_H | ||
|
|
||
| #include <__config> | ||
| #include <exception> | ||
|
|
||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
| # pragma GCC system_header | ||
| #endif | ||
|
|
||
| #if _LIBCPP_STD_VER >= 17 | ||
|
|
||
| _LIBCPP_BEGIN_NAMESPACE_STD | ||
|
|
||
| # ifndef _LIBCPP_HAS_NO_EXCEPTIONS | ||
|
|
||
| template <class _Func> | ||
| _LIBCPP_HIDE_FROM_ABI auto __terminate_on_exception(_Func __func) { | ||
| try { | ||
| return __func(); | ||
| } catch (...) { | ||
| std::terminate(); | ||
| } | ||
| } | ||
|
|
||
| # else // _LIBCPP_HAS_NO_EXCEPTIONS | ||
|
|
||
| template <class _Func> | ||
| _LIBCPP_HIDE_FROM_ABI auto __terminate_on_exception(_Func __func) { | ||
| return __func(); | ||
| } | ||
|
|
||
| # endif // _LIBCPP_HAS_NO_EXCEPTIONS | ||
|
|
||
| _LIBCPP_END_NAMESPACE_STD | ||
|
|
||
| #endif // _LIBCPP_STD_VER >= 17 | ||
|
|
||
| #endif // _LIBCPP___UTILITY_TERMINATE_ON_EXCEPTION_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Check that PSTL algorithms aren't marked [[nodiscard]] when | ||
| // _LIBCPP_DISBALE_NODISCARD_EXT is defined | ||
|
|
||
| // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_NODISCARD_EXT | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| #include <algorithm> | ||
| #include <execution> | ||
|
|
||
| void test() { | ||
| int a[] = {1}; | ||
| auto pred = [](auto) { return false; }; | ||
| std::all_of(std::execution::par, std::begin(a), std::end(a), pred); | ||
| std::any_of(std::execution::par, std::begin(a), std::end(a), pred); | ||
| std::none_of(std::execution::par, std::begin(a), std::end(a), pred); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Check that PSTL algorithms are marked [[nodiscard]] as a conforming extension | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| #include <algorithm> | ||
| #include <execution> | ||
|
|
||
| void test() { | ||
| int a[] = {1}; | ||
| auto pred = [](auto) { return false; }; | ||
| std::all_of(std::execution::par, std::begin(a), std::end(a), pred); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| std::any_of(std::execution::par, std::begin(a), std::end(a), pred); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| std::none_of(std::execution::par, std::begin(a), std::end(a), pred); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // Make sure we don't allow copying the execution policies in any way to avoid users relying on it. | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| #include <execution> | ||
| #include <type_traits> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| static_assert(!std::is_default_constructible_v<std::execution::sequenced_policy>); | ||
| static_assert(!std::is_copy_constructible_v<std::execution::sequenced_policy>); | ||
| static_assert(!std::is_move_constructible_v<std::execution::sequenced_policy>); | ||
| static_assert(!std::is_copy_assignable_v<std::execution::sequenced_policy>); | ||
| static_assert(!std::is_move_assignable_v<std::execution::sequenced_policy>); | ||
|
|
||
| static_assert(!std::is_default_constructible_v<std::execution::parallel_policy>); | ||
| static_assert(!std::is_copy_constructible_v<std::execution::parallel_policy>); | ||
| static_assert(!std::is_move_constructible_v<std::execution::parallel_policy>); | ||
| static_assert(!std::is_copy_assignable_v<std::execution::parallel_policy>); | ||
| static_assert(!std::is_move_assignable_v<std::execution::parallel_policy>); | ||
|
|
||
| static_assert(!std::is_default_constructible_v<std::execution::parallel_unsequenced_policy>); | ||
| static_assert(!std::is_copy_constructible_v<std::execution::parallel_unsequenced_policy>); | ||
| static_assert(!std::is_move_constructible_v<std::execution::parallel_unsequenced_policy>); | ||
| static_assert(!std::is_copy_assignable_v<std::execution::parallel_unsequenced_policy>); | ||
| static_assert(!std::is_move_assignable_v<std::execution::parallel_unsequenced_policy>); | ||
|
|
||
| #if TEST_STD_VER >= 20 | ||
| static_assert(!std::is_default_constructible_v<std::execution::unsequenced_policy>); | ||
| static_assert(!std::is_copy_constructible_v<std::execution::unsequenced_policy>); | ||
| static_assert(!std::is_move_constructible_v<std::execution::unsequenced_policy>); | ||
| static_assert(!std::is_copy_assignable_v<std::execution::unsequenced_policy>); | ||
| static_assert(!std::is_move_assignable_v<std::execution::unsequenced_policy>); | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| // <algorithm> | ||
|
|
||
| // template<class ExecutionPolicy, class ForwardIterator, class Predicate> | ||
| // bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, | ||
| // Predicate pred); | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <vector> | ||
|
|
||
| #include "test_macros.h" | ||
| #include "test_execution_policies.h" | ||
| #include "test_iterators.h" | ||
|
|
||
| EXECUTION_POLICY_SFINAE_TEST(all_of); | ||
|
|
||
| static_assert(sfinae_test_all_of<int, int*, int*, bool (*)(int)>); | ||
| static_assert(!sfinae_test_all_of<std::execution::parallel_policy, int*, int*, bool (*)(int)>); | ||
|
|
||
| template <class Iter> | ||
| struct Test { | ||
| template <class Policy> | ||
| void operator()(Policy&& policy) { | ||
| int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; | ||
| // simple test | ||
| assert(std::all_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i < 9; })); | ||
| assert(!std::all_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i < 8; })); | ||
|
|
||
| // check that an empty range works | ||
| assert(std::all_of(policy, Iter(std::begin(a)), Iter(std::begin(a)), [](int) { return true; })); | ||
|
|
||
| // check that a single-element range works | ||
| assert(std::all_of(policy, Iter(a), Iter(a + 1), [](int i) { return i < 2; })); | ||
|
|
||
| // check that a two-element range works | ||
| assert(std::all_of(policy, Iter(a), Iter(a + 2), [](int i) { return i < 3; })); | ||
|
|
||
| // check that false is returned if no element satisfies the condition | ||
| assert(!std::all_of(policy, Iter(std::begin(a)), Iter(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, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i == 1; })); | ||
|
|
||
| // check that a one-element range works | ||
| assert(std::all_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 1), [](int i) { return i == 1; })); | ||
|
|
||
| // check that a two-element range works | ||
| assert(std::all_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 2), [](int i) { return i < 3; })); | ||
|
|
||
| // check that a large number of elements works | ||
| std::vector<int> vec(100); | ||
| std::fill(vec.begin(), vec.end(), 3); | ||
| assert(std::all_of(Iter(vec.data()), Iter(vec.data() + vec.size()), [](int i) { return i == 3; })); | ||
| } | ||
| }; | ||
|
|
||
| int main(int, char**) { | ||
| types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{}); | ||
|
|
||
| #ifndef TEST_HAS_NO_EXCEPTIONS | ||
| std::set_terminate(terminate_successful); | ||
| int a[] = {1, 2}; | ||
| try { | ||
| (void)std::all_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); | ||
| } catch (int) { | ||
| assert(false); | ||
| } | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| // <algorithm> | ||
|
|
||
| // template<class ExecutionPolicy, class ForwardIterator, class Predicate> | ||
| // bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, | ||
| // Predicate pred); | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <vector> | ||
|
|
||
| #include "test_macros.h" | ||
| #include "test_execution_policies.h" | ||
| #include "test_iterators.h" | ||
|
|
||
| EXECUTION_POLICY_SFINAE_TEST(any_of); | ||
|
|
||
| static_assert(sfinae_test_any_of<int, int*, int*, bool (*)(int)>); | ||
| static_assert(!sfinae_test_any_of<std::execution::parallel_policy, int*, int*, bool (*)(int)>); | ||
|
|
||
| template <class Iter> | ||
| struct Test { | ||
| template <class Policy> | ||
| void operator()(Policy&& policy) { | ||
| int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; | ||
| // simple test | ||
| assert(std::any_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i < 9; })); | ||
| assert(!std::any_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i > 8; })); | ||
|
|
||
| // check that an empty range works | ||
| assert(!std::any_of(policy, Iter(std::begin(a)), Iter(std::begin(a)), [](int) { return false; })); | ||
|
|
||
| // check that false is returned if no element satisfies the condition | ||
| assert(!std::any_of(policy, Iter(std::begin(a)), Iter(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, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i == 1; })); | ||
|
|
||
| // check that a one-element range works | ||
| assert(std::any_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 1), [](int i) { return i == 1; })); | ||
|
|
||
| // check that a two-element range works | ||
| assert(std::any_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 2), [](int i) { return i == 2; })); | ||
|
|
||
| // check that a large number of elements works | ||
| std::vector<int> vec(100, 2); | ||
| vec[96] = 3; | ||
| assert(std::any_of(Iter(vec.data()), Iter(vec.data() + vec.size()), [](int i) { return i == 3; })); | ||
| } | ||
| }; | ||
|
|
||
| int main(int, char**) { | ||
| types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{}); | ||
|
|
||
| #ifndef TEST_HAS_NO_EXCEPTIONS | ||
| std::set_terminate(terminate_successful); | ||
| int a[] = {1, 2}; | ||
| try { | ||
| (void)std::any_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); | ||
| } catch (int) { | ||
| assert(false); | ||
| } | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
|
|
||
| // <algorithm> | ||
|
|
||
| // template<class ExecutionPolicy, class ForwardIterator, class Predicate> | ||
| // bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, | ||
| // Predicate pred); | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <vector> | ||
|
|
||
| #include "test_macros.h" | ||
| #include "test_execution_policies.h" | ||
| #include "test_iterators.h" | ||
|
|
||
| EXECUTION_POLICY_SFINAE_TEST(none_of); | ||
|
|
||
| static_assert(sfinae_test_none_of<int, int*, int*, bool (*)(int)>); | ||
| static_assert(!sfinae_test_none_of<std::execution::parallel_policy, int*, int*, bool (*)(int)>); | ||
|
|
||
| template <class Iter> | ||
| struct Test { | ||
| template <class Policy> | ||
| void operator()(Policy&& policy) { | ||
| int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; | ||
| // simple test | ||
| assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i > 9; })); | ||
| assert(!std::none_of(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i >= 8; })); | ||
|
|
||
| // check that an empty range works | ||
| assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::begin(a)), [](int) { return false; })); | ||
|
|
||
| // check that true is returned if no element satisfies the condition | ||
| assert(std::none_of(policy, Iter(std::begin(a)), Iter(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, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i == 1; })); | ||
|
|
||
| // check that a one-element range works | ||
| assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 1), [](int i) { return i != 1; })); | ||
|
|
||
| // check that a two-element range works | ||
| assert(std::none_of(policy, Iter(std::begin(a)), Iter(std::begin(a) + 2), [](int i) { return i > 2; })); | ||
|
|
||
| // check that a large number of elements works | ||
| std::vector<int> vec(100); | ||
| std::fill(vec.begin(), vec.end(), 3); | ||
| assert(std::none_of(Iter(vec.data()), Iter(vec.data() + vec.size()), [](int i) { return i != 3; })); | ||
| } | ||
| }; | ||
|
|
||
| int main(int, char**) { | ||
| types::for_each(types::forward_iterator_list<int*>{}, TestIteratorWithPolicies<Test>{}); | ||
|
|
||
| #ifndef TEST_HAS_NO_EXCEPTIONS | ||
| std::set_terminate(terminate_successful); | ||
| int a[] = {1, 2}; | ||
| try { | ||
| (void)std::none_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); | ||
| } catch (int) { | ||
| assert(false); | ||
| } | ||
| #endif | ||
|
|
||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // template<class T> struct is_execution_policy; | ||
| // template<class T> constexpr bool is_execution_policy_v = is_execution_policy<T>::value; | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| #include <execution> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| static_assert(std::is_execution_policy<std::execution::sequenced_policy>::value); | ||
| static_assert(std::is_execution_policy_v<std::execution::sequenced_policy>); | ||
| static_assert(std::is_execution_policy<std::execution::parallel_policy>::value); | ||
| static_assert(std::is_execution_policy_v<std::execution::parallel_policy>); | ||
| static_assert(std::is_execution_policy<std::execution::parallel_unsequenced_policy>::value); | ||
| static_assert(std::is_execution_policy_v<std::execution::parallel_unsequenced_policy>); | ||
|
|
||
| #if TEST_STD_VER >= 20 | ||
| static_assert(std::is_execution_policy<std::execution::unsequenced_policy>::value); | ||
| static_assert(std::is_execution_policy_v<std::execution::unsequenced_policy>); | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // class sequenced_policy; | ||
| // class parallel_policy; | ||
| // class parallel_unsequenced_policy; | ||
| // class unsequenced_policy; // since C++20 | ||
| // | ||
| // inline constexpr sequenced_policy seq = implementation-defined; | ||
| // inline constexpr parallel_policy par = implementation-defined; | ||
| // inline constexpr parallel_unsequenced_policy par_unseq = implementation-defined; | ||
| // inline constexpr unsequenced_policy unseq = implementation-defined; // since C++20 | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14 | ||
|
|
||
| // REQUIRES: with-pstl | ||
|
|
||
| #include <execution> | ||
| #include <type_traits> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| template <class T> | ||
| using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>; | ||
|
|
||
| template <class T> | ||
| TEST_NOINLINE void use(T&) {} | ||
|
|
||
| static_assert(std::is_same_v<remove_cvref_t<decltype(std::execution::seq)>, std::execution::sequenced_policy>); | ||
| static_assert(std::is_same_v<remove_cvref_t<decltype(std::execution::par)>, std::execution::parallel_policy>); | ||
| static_assert( | ||
| std::is_same_v<remove_cvref_t<decltype(std::execution::par_unseq)>, std::execution::parallel_unsequenced_policy>); | ||
|
|
||
| #if TEST_STD_VER >= 20 | ||
| static_assert(std::is_same_v<remove_cvref_t<decltype(std::execution::unseq)>, std::execution::unsequenced_policy>); | ||
| #endif | ||
|
|
||
| int main(int, char**) { | ||
| use(std::execution::seq); | ||
| use(std::execution::par); | ||
| use(std::execution::par_unseq); | ||
| #if TEST_STD_VER >= 20 | ||
| use(std::execution::unseq); | ||
| #endif | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 <cstdlib> | ||
| #include <execution> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| #define EXECUTION_POLICY_SFINAE_TEST(function) \ | ||
| template <class, class...> \ | ||
| struct sfinae_test_##function##_impl : std::true_type {}; \ | ||
| \ | ||
| template <class... Args> \ | ||
| struct sfinae_test_##function##_impl<std::void_t<decltype(std::function(std::declval<Args>()...))>, Args...> \ | ||
| : std::false_type {}; \ | ||
| \ | ||
| template <class... Args> \ | ||
| constexpr bool sfinae_test_##function = sfinae_test_##function##_impl<void, Args...>::value; | ||
|
|
||
| template <class Functor> | ||
| 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; | ||
| } | ||
|
|
||
| template <template <class Iter> class TestClass> | ||
| struct TestIteratorWithPolicies { | ||
| template <class Iter> | ||
| void operator()() { | ||
| test_execution_policies(TestClass<Iter>{}); | ||
| } | ||
| }; | ||
|
|
||
| [[noreturn]] inline void terminate_successful() { std::exit(0); } | ||
|
|
||
| #endif // TEST_SUPPORT_TEST_EXECUTION_POLICIES |