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___ALGORITHM_PSTL_FRONTEND_DISPATCH
10#define _LIBCPP___ALGORITHM_PSTL_FRONTEND_DISPATCH
11
12#include <__config>
13#include <__type_traits/is_callable.h>
14#include <__utility/forward.h>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#  pragma GCC system_header
18#endif
19
20#if _LIBCPP_STD_VER >= 17
21
22_LIBCPP_BEGIN_NAMESPACE_STD
23
24#  define _LIBCPP_PSTL_CUSTOMIZATION_POINT(name, policy)                                                               \
25    [](auto&&... __args) -> decltype(std::name<policy>(                                                                \
26                             typename __select_backend<policy>::type{}, std::forward<decltype(__args)>(__args)...)) {  \
27      return std::name<policy>(typename __select_backend<policy>::type{}, std::forward<decltype(__args)>(__args)...);  \
28    }
29
30template <class _SpecializedImpl, class _GenericImpl, class... _Args>
31_LIBCPP_HIDE_FROM_ABI decltype(auto)
32__pstl_frontend_dispatch(_SpecializedImpl __specialized_impl, _GenericImpl __generic_impl, _Args&&... __args) {
33  if constexpr (__is_callable<_SpecializedImpl, _Args...>::value) {
34    return __specialized_impl(std::forward<_Args>(__args)...);
35  } else {
36    return __generic_impl(std::forward<_Args>(__args)...);
37  }
38}
39
40_LIBCPP_END_NAMESPACE_STD
41
42#endif // _LIBCPP_STD_VER >= 17
43
44#endif // _LIBCPP___ALGORITHM_PSTL_FRONTEND_DISPATCH
45