Path: blob/main/contrib/llvm-project/libcxx/include/__functional/bind_back.h
35260 views
// -*- C++ -*-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-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___FUNCTIONAL_BIND_BACK_H10#define _LIBCPP___FUNCTIONAL_BIND_BACK_H1112#include <__config>13#include <__functional/invoke.h>14#include <__functional/perfect_forward.h>15#include <__type_traits/decay.h>16#include <__utility/forward.h>17#include <__utility/integer_sequence.h>18#include <tuple>1920#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21# pragma GCC system_header22#endif2324_LIBCPP_BEGIN_NAMESPACE_STD2526#if _LIBCPP_STD_VER >= 202728template <size_t _NBound, class = make_index_sequence<_NBound>>29struct __bind_back_op;3031template <size_t _NBound, size_t... _Ip>32struct __bind_back_op<_NBound, index_sequence<_Ip...>> {33template <class _Fn, class _BoundArgs, class... _Args>34_LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const35noexcept(noexcept(std::invoke(std::forward<_Fn>(__f),36std::forward<_Args>(__args)...,37std::get<_Ip>(std::forward<_BoundArgs>(__bound_args))...)))38-> decltype(std::invoke(std::forward<_Fn>(__f),39std::forward<_Args>(__args)...,40std::get<_Ip>(std::forward<_BoundArgs>(__bound_args))...)) {41return std::invoke(std::forward<_Fn>(__f),42std::forward<_Args>(__args)...,43std::get<_Ip>(std::forward<_BoundArgs>(__bound_args))...);44}45};4647template <class _Fn, class _BoundArgs>48struct __bind_back_t : __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs> {49using __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs>::__perfect_forward;50};5152template <class _Fn, class... _Args>53requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> &&54(is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...)55_LIBCPP_HIDE_FROM_ABI constexpr auto __bind_back(_Fn&& __f, _Args&&... __args) noexcept(56noexcept(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(57std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...))))58-> decltype(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(59std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...))) {60return __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(61std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...));62}6364# if _LIBCPP_STD_VER >= 2365template <class _Fn, class... _Args>66_LIBCPP_HIDE_FROM_ABI constexpr auto bind_back(_Fn&& __f, _Args&&... __args) {67static_assert(is_constructible_v<decay_t<_Fn>, _Fn>, "bind_back requires decay_t<F> to be constructible from F");68static_assert(is_move_constructible_v<decay_t<_Fn>>, "bind_back requires decay_t<F> to be move constructible");69static_assert((is_constructible_v<decay_t<_Args>, _Args> && ...),70"bind_back requires all decay_t<Args> to be constructible from respective Args");71static_assert((is_move_constructible_v<decay_t<_Args>> && ...),72"bind_back requires all decay_t<Args> to be move constructible");73return __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(74std::forward<_Fn>(__f), std::forward_as_tuple(std::forward<_Args>(__args)...));75}76# endif // _LIBCPP_STD_VER >= 237778#endif // _LIBCPP_STD_VER >= 207980_LIBCPP_END_NAMESPACE_STD8182#endif // _LIBCPP___FUNCTIONAL_BIND_BACK_H838485