File indexing completed on 2026-05-03 08:13:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_MAKE_PROJECTED_H
0010 #define _LIBCPP___CXX03___ALGORITHM_MAKE_PROJECTED_H
0011
0012 #include <__cxx03/__concepts/same_as.h>
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__functional/identity.h>
0015 #include <__cxx03/__functional/invoke.h>
0016 #include <__cxx03/__type_traits/decay.h>
0017 #include <__cxx03/__type_traits/enable_if.h>
0018 #include <__cxx03/__type_traits/integral_constant.h>
0019 #include <__cxx03/__type_traits/is_member_pointer.h>
0020 #include <__cxx03/__type_traits/is_same.h>
0021 #include <__cxx03/__utility/declval.h>
0022 #include <__cxx03/__utility/forward.h>
0023
0024 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0025 # pragma GCC system_header
0026 #endif
0027
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029
0030 template <class _Pred, class _Proj>
0031 struct _ProjectedPred {
0032 _Pred& __pred;
0033 _Proj& __proj;
0034
0035 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI _ProjectedPred(_Pred& __pred_arg, _Proj& __proj_arg)
0036 : __pred(__pred_arg), __proj(__proj_arg) {}
0037
0038 template <class _Tp>
0039 typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))>::type
0040 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
0041 operator()(_Tp&& __v) const {
0042 return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v)));
0043 }
0044
0045 template <class _T1, class _T2>
0046 typename __invoke_of<_Pred&,
0047 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())),
0048 decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))>::type _LIBCPP_CONSTEXPR
0049 _LIBCPP_HIDE_FROM_ABI
0050 operator()(_T1&& __lhs, _T2&& __rhs) const {
0051 return std::__invoke(
0052 __pred, std::__invoke(__proj, std::forward<_T1>(__lhs)), std::__invoke(__proj, std::forward<_T2>(__rhs)));
0053 }
0054 };
0055
0056 template <
0057 class _Pred,
0058 class _Proj,
0059 __enable_if_t<!(!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value), int> = 0>
0060 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ProjectedPred<_Pred, _Proj> __make_projected(_Pred& __pred, _Proj& __proj) {
0061 return _ProjectedPred<_Pred, _Proj>(__pred, __proj);
0062 }
0063
0064
0065
0066
0067 template <
0068 class _Pred,
0069 class _Proj,
0070 __enable_if_t<!is_member_pointer<__decay_t<_Pred> >::value && __is_identity<__decay_t<_Proj> >::value, int> = 0>
0071 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Pred& __make_projected(_Pred& __pred, _Proj&) {
0072 return __pred;
0073 }
0074
0075 _LIBCPP_END_NAMESPACE_STD
0076
0077 #if _LIBCPP_STD_VER >= 20
0078
0079 _LIBCPP_BEGIN_NAMESPACE_STD
0080
0081 namespace ranges {
0082
0083 template <class _Comp, class _Proj1, class _Proj2>
0084 _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __make_projected_comp(_Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) {
0085 if constexpr (__is_identity<decay_t<_Proj1>>::value && __is_identity<decay_t<_Proj2>>::value &&
0086 !is_member_pointer_v<decay_t<_Comp>>) {
0087
0088
0089 return __comp;
0090
0091 } else {
0092 return [&](auto&& __lhs, auto&& __rhs) -> bool {
0093 return std::invoke(__comp,
0094 std::invoke(__proj1, std::forward<decltype(__lhs)>(__lhs)),
0095 std::invoke(__proj2, std::forward<decltype(__rhs)>(__rhs)));
0096 };
0097 }
0098 }
0099
0100 }
0101
0102 _LIBCPP_END_NAMESPACE_STD
0103
0104 #endif
0105
0106 #endif