xref: /freebsd/contrib/llvm-project/libcxx/include/__functional/bind_front.h (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
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_FRONT_H
11 #define _LIBCPP___FUNCTIONAL_BIND_FRONT_H
12 
13 #include <__config>
14 #include <__functional/invoke.h>
15 #include <__functional/perfect_forward.h>
16 #include <__utility/forward.h>
17 #include <type_traits>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 #if _LIBCPP_STD_VER > 17
26 
27 struct __bind_front_op {
28     template <class ..._Args>
29     _LIBCPP_HIDE_FROM_ABI
30     constexpr auto operator()(_Args&& ...__args) const
31         noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
32         -> decltype(      _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
33         { return          _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
34 };
35 
36 template <class _Fn, class ..._BoundArgs>
37 struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
38     using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward;
39 };
40 
41 template <class _Fn, class... _Args, class = enable_if_t<
42     _And<
43         is_constructible<decay_t<_Fn>, _Fn>,
44         is_move_constructible<decay_t<_Fn>>,
45         is_constructible<decay_t<_Args>, _Args>...,
46         is_move_constructible<decay_t<_Args>>...
47     >::value
48 >>
49 _LIBCPP_HIDE_FROM_ABI
50 constexpr auto bind_front(_Fn&& __f, _Args&&... __args) {
51     return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
52 }
53 
54 #endif // _LIBCPP_STD_VER > 17
55 
56 _LIBCPP_END_NAMESPACE_STD
57 
58 #endif // _LIBCPP___FUNCTIONAL_BIND_FRONT_H
59