File indexing completed on 2026-05-03 08:13:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___FUNCTIONAL_BIND_BACK_H
0011 #define _LIBCPP___FUNCTIONAL_BIND_BACK_H
0012
0013 #include <__config>
0014 #include <__functional/invoke.h>
0015 #include <__functional/perfect_forward.h>
0016 #include <__type_traits/decay.h>
0017 #include <__utility/forward.h>
0018 #include <__utility/integer_sequence.h>
0019 #include <tuple>
0020
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 # pragma GCC system_header
0023 #endif
0024
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026
0027 #if _LIBCPP_STD_VER >= 20
0028
0029 template <size_t _NBound, class = make_index_sequence<_NBound>>
0030 struct __bind_back_op;
0031
0032 template <size_t _NBound, size_t... _Ip>
0033 struct __bind_back_op<_NBound, index_sequence<_Ip...>> {
0034 template <class _Fn, class _BoundArgs, class... _Args>
0035 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const
0036 noexcept(noexcept(std::invoke(std::forward<_Fn>(__f),
0037 std::forward<_Args>(__args)...,
0038 std::get<_Ip>(std::forward<_BoundArgs>(__bound_args))...)))
0039 -> decltype(std::invoke(std::forward<_Fn>(__f),
0040 std::forward<_Args>(__args)...,
0041 std::get<_Ip>(std::forward<_BoundArgs>(__bound_args))...)) {
0042 return std::invoke(std::forward<_Fn>(__f),
0043 std::forward<_Args>(__args)...,
0044 std::get<_Ip>(std::forward<_BoundArgs>(__bound_args))...);
0045 }
0046 };
0047
0048 template <class _Fn, class _BoundArgs>
0049 struct __bind_back_t : __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs> {
0050 using __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs>::__perfect_forward;
0051 };
0052
0053 template <class _Fn, class... _Args>
0054 requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> &&
0055 (is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...)
0056 _LIBCPP_HIDE_FROM_ABI constexpr auto __bind_back(_Fn&& __f, _Args&&... __args) noexcept(
0057 noexcept(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(
0058 std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...))))
0059 -> decltype(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(
0060 std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...))) {
0061 return __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(
0062 std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...));
0063 }
0064
0065 # if _LIBCPP_STD_VER >= 23
0066 template <class _Fn, class... _Args>
0067 _LIBCPP_HIDE_FROM_ABI constexpr auto bind_back(_Fn&& __f, _Args&&... __args) {
0068 static_assert(is_constructible_v<decay_t<_Fn>, _Fn>, "bind_back requires decay_t<F> to be constructible from F");
0069 static_assert(is_move_constructible_v<decay_t<_Fn>>, "bind_back requires decay_t<F> to be move constructible");
0070 static_assert((is_constructible_v<decay_t<_Args>, _Args> && ...),
0071 "bind_back requires all decay_t<Args> to be constructible from respective Args");
0072 static_assert((is_move_constructible_v<decay_t<_Args>> && ...),
0073 "bind_back requires all decay_t<Args> to be move constructible");
0074 return __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(
0075 std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...));
0076 }
0077 # endif
0078
0079 #endif
0080
0081 _LIBCPP_END_NAMESPACE_STD
0082
0083 #endif