[libc] Add base for target config within cmake (#72318)
[llvm-project.git] / libcxx / test / support / test_execution_policies.h
blob65569bbec0836bfa200b3fe152778bed8c08ec0e
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef TEST_SUPPORT_TEST_EXECUTION_POLICIES
10 #define TEST_SUPPORT_TEST_EXECUTION_POLICIES
12 #include <cstdlib>
13 #include <exception>
14 #include <execution>
15 #include <type_traits>
16 #include <utility>
18 #include "test_macros.h"
20 #define EXECUTION_POLICY_SFINAE_TEST(function) \
21 template <class, class...> \
22 struct sfinae_test_##function##_impl : std::true_type {}; \
24 template <class... Args> \
25 struct sfinae_test_##function##_impl<std::void_t<decltype(std::function(std::declval<Args>()...))>, Args...> \
26 : std::false_type {}; \
28 template <class... Args> \
29 constexpr bool sfinae_test_##function = sfinae_test_##function##_impl<void, Args...>::value;
31 template <class Functor>
32 bool test_execution_policies(Functor func) {
33 func(std::execution::seq);
34 #if TEST_STD_VER >= 20
35 func(std::execution::unseq);
36 #endif
37 func(std::execution::par);
38 func(std::execution::par_unseq);
40 return true;
43 template <template <class Iter> class TestClass>
44 struct TestIteratorWithPolicies {
45 template <class Iter>
46 void operator()() {
47 test_execution_policies(TestClass<Iter>{});
51 struct Bool {
52 bool b_;
53 Bool() = default;
54 Bool(bool b) : b_(b) {}
56 operator bool&() {
57 return b_;
61 #endif // TEST_SUPPORT_TEST_EXECUTION_POLICIES