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 _LIBCPP___PSTL_DISPATCH_H |
10 | #define _LIBCPP___PSTL_DISPATCH_H |
11 | |
12 | #include <__config> |
13 | #include <__pstl/backend_fwd.h> |
14 | #include <__type_traits/conditional.h> |
15 | #include <__type_traits/enable_if.h> |
16 | #include <__type_traits/integral_constant.h> |
17 | #include <__type_traits/type_identity.h> |
18 | |
19 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
20 | # pragma GCC system_header |
21 | #endif |
22 | |
23 | _LIBCPP_PUSH_MACROS |
24 | #include <__undef_macros> |
25 | |
26 | #if _LIBCPP_STD_VER >= 17 |
27 | |
28 | _LIBCPP_BEGIN_NAMESPACE_STD |
29 | namespace __pstl { |
30 | |
31 | template <template <class, class> class _Algorithm, class _Backend, class _ExecutionPolicy, class = void> |
32 | constexpr bool __is_implemented_v = false; |
33 | |
34 | template <template <class, class> class _Algorithm, class _Backend, class _ExecutionPolicy> |
35 | constexpr bool __is_implemented_v<_Algorithm, |
36 | _Backend, |
37 | _ExecutionPolicy, |
38 | __enable_if_t<sizeof(_Algorithm<_Backend, _ExecutionPolicy>)>> = true; |
39 | |
40 | // Helpful to provide better error messages. This will show the algorithm and the execution policy |
41 | // in the compiler diagnostic. |
42 | template <template <class, class> class _Algorithm, class _ExecutionPolicy> |
43 | constexpr bool __cant_find_backend_for = false; |
44 | |
45 | template <template <class, class> class _Algorithm, class _BackendConfiguration, class _ExecutionPolicy> |
46 | struct __find_first_implemented; |
47 | |
48 | template <template <class, class> class _Algorithm, class _ExecutionPolicy> |
49 | struct __find_first_implemented<_Algorithm, __backend_configuration<>, _ExecutionPolicy> { |
50 | static_assert(__cant_find_backend_for<_Algorithm, _ExecutionPolicy>, |
51 | "Could not find a PSTL backend for the given algorithm and execution policy" ); |
52 | }; |
53 | |
54 | template <template <class, class> class _Algorithm, class _B1, class... _Bn, class _ExecutionPolicy> |
55 | struct __find_first_implemented<_Algorithm, __backend_configuration<_B1, _Bn...>, _ExecutionPolicy> |
56 | : _If<__is_implemented_v<_Algorithm, _B1, _ExecutionPolicy>, |
57 | __type_identity<_Algorithm<_B1, _ExecutionPolicy>>, |
58 | __find_first_implemented<_Algorithm, __backend_configuration<_Bn...>, _ExecutionPolicy> > {}; |
59 | |
60 | template <template <class, class> class _Algorithm, class _BackendConfiguration, class _ExecutionPolicy> |
61 | using __dispatch _LIBCPP_NODEBUG = |
62 | typename __find_first_implemented<_Algorithm, _BackendConfiguration, _ExecutionPolicy>::type; |
63 | |
64 | } // namespace __pstl |
65 | _LIBCPP_END_NAMESPACE_STD |
66 | |
67 | #endif // _LIBCPP_STD_VER >= 17 |
68 | |
69 | _LIBCPP_POP_MACROS |
70 | |
71 | #endif // _LIBCPP___PSTL_DISPATCH_H |
72 | |