• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___FUNCTIONAL_BIND_BACK_H
11 #define _LIBCPP___FUNCTIONAL_BIND_BACK_H
12 
13 #include <__config>
14 #include <__functional/invoke.h>
15 #include <__functional/perfect_forward.h>
16 #include <__utility/forward.h>
17 #include <__utility/integer_sequence.h>
18 #include <tuple>
19 
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #  pragma GCC system_header
22 #endif
23 
24 _LIBCPP_BEGIN_NAMESPACE_STD
25 
26 #if _LIBCPP_STD_VER >= 20
27 
28 template <size_t _NBound, class = make_index_sequence<_NBound>>
29 struct __bind_back_op;
30 
31 template <size_t _NBound, size_t ..._Ip>
32 struct __bind_back_op<_NBound, index_sequence<_Ip...>> {
33     template <class _Fn, class _BoundArgs, class... _Args>
34     _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const
35         noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...)))
36         -> decltype(      _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...))
37         { return          _VSTD::invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)..., _VSTD::get<_Ip>(_VSTD::forward<_BoundArgs>(__bound_args))...); }
38 };
39 
40 template <class _Fn, class _BoundArgs>
41 struct __bind_back_t : __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs> {
42     using __perfect_forward<__bind_back_op<tuple_size_v<_BoundArgs>>, _Fn, _BoundArgs>::__perfect_forward;
43 };
44 
45 template <class _Fn, class ..._Args, class = enable_if_t<
46     _And<
47         is_constructible<decay_t<_Fn>, _Fn>,
48         is_move_constructible<decay_t<_Fn>>,
49         is_constructible<decay_t<_Args>, _Args>...,
50         is_move_constructible<decay_t<_Args>>...
51     >::value
52 >>
53 _LIBCPP_HIDE_FROM_ABI
54 constexpr auto __bind_back(_Fn&& __f, _Args&&... __args)
55     noexcept(noexcept(__bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...))))
56     -> decltype(      __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)))
57     { return          __bind_back_t<decay_t<_Fn>, tuple<decay_t<_Args>...>>(_VSTD::forward<_Fn>(__f), _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)); }
58 
59 #endif // _LIBCPP_STD_VER >= 20
60 
61 _LIBCPP_END_NAMESPACE_STD
62 
63 #endif // _LIBCPP___FUNCTIONAL_BIND_BACK_H
64