xref: /llvm-project/libcxx/test/support/test_execution_policies.h (revision aade74675c15d3bae5fdfa67f7b4b6ed9dac3d20)
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 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEST_SUPPORT_TEST_EXECUTION_POLICIES
10 #define TEST_SUPPORT_TEST_EXECUTION_POLICIES
11 
12 #include <cstdlib>
13 #include <exception>
14 #include <execution>
15 #include <type_traits>
16 #include <utility>
17 
18 #include "test_macros.h"
19 
20 #define EXECUTION_POLICY_SFINAE_TEST(function)                                                                         \
21   template <class, class...>                                                                                           \
22   struct sfinae_test_##function##_impl : std::true_type {};                                                            \
23                                                                                                                        \
24   template <class... Args>                                                                                             \
25   struct sfinae_test_##function##_impl<std::void_t<decltype(std::function(std::declval<Args>()...))>, Args...>         \
26       : std::false_type {};                                                                                            \
27                                                                                                                        \
28   template <class... Args>                                                                                             \
29   constexpr bool sfinae_test_##function = sfinae_test_##function##_impl<void, Args...>::value;
30 
31 template <class Functor>
test_execution_policies(Functor func)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);
39 
40   return true;
41 }
42 
43 template <template <class Iter> class TestClass>
44 struct TestIteratorWithPolicies {
45   template <class Iter>
operatorTestIteratorWithPolicies46   void operator()() {
47     test_execution_policies(TestClass<Iter>{});
48   }
49 };
50 
51 struct Bool {
52   bool b_;
53   Bool() = default;
BoolBool54   Bool(bool b) : b_(b) {}
55 
56   operator bool&() {
57     return b_;
58   }
59 };
60 
61 #endif // TEST_SUPPORT_TEST_EXECUTION_POLICIES
62