1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___PSTL_DISPATCH_H
10 #define _LIBCPP___PSTL_DISPATCH_H
12 #include <__cxx03/__config>
13 #include <__cxx03/__pstl/backend_fwd.h>
14 #include <__cxx03/__type_traits/conditional.h>
15 #include <__cxx03/__type_traits/enable_if.h>
16 #include <__cxx03/__type_traits/integral_constant.h>
17 #include <__cxx03/__type_traits/type_identity.h>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
24 #include <__cxx03/__undef_macros>
26 _LIBCPP_BEGIN_NAMESPACE_STD
29 template <template <class, class> class _Algorithm
, class _Backend
, class _ExecutionPolicy
, class = void>
30 constexpr bool __is_implemented_v
= false;
32 template <template <class, class> class _Algorithm
, class _Backend
, class _ExecutionPolicy
>
33 constexpr bool __is_implemented_v
<_Algorithm
,
36 __enable_if_t
<sizeof(_Algorithm
<_Backend
, _ExecutionPolicy
>)>> = true;
38 // Helpful to provide better error messages. This will show the algorithm and the execution policy
39 // in the compiler diagnostic.
40 template <template <class, class> class _Algorithm
, class _ExecutionPolicy
>
41 constexpr bool __cant_find_backend_for
= false;
43 template <template <class, class> class _Algorithm
, class _BackendConfiguration
, class _ExecutionPolicy
>
44 struct __find_first_implemented
;
46 template <template <class, class> class _Algorithm
, class _ExecutionPolicy
>
47 struct __find_first_implemented
<_Algorithm
, __backend_configuration
<>, _ExecutionPolicy
> {
48 static_assert(__cant_find_backend_for
<_Algorithm
, _ExecutionPolicy
>,
49 "Could not find a PSTL backend for the given algorithm and execution policy");
52 template <template <class, class> class _Algorithm
, class _B1
, class... _Bn
, class _ExecutionPolicy
>
53 struct __find_first_implemented
<_Algorithm
, __backend_configuration
<_B1
, _Bn
...>, _ExecutionPolicy
>
54 : _If
<__is_implemented_v
<_Algorithm
, _B1
, _ExecutionPolicy
>,
55 __type_identity
<_Algorithm
<_B1
, _ExecutionPolicy
>>,
56 __find_first_implemented
<_Algorithm
, __backend_configuration
<_Bn
...>, _ExecutionPolicy
> > {};
58 template <template <class, class> class _Algorithm
, class _BackendConfiguration
, class _ExecutionPolicy
>
59 using __dispatch
= typename __find_first_implemented
<_Algorithm
, _BackendConfiguration
, _ExecutionPolicy
>::type
;
62 _LIBCPP_END_NAMESPACE_STD
66 #endif // _LIBCPP___PSTL_DISPATCH_H