Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __functional / bind_front.h
blob7ccd6e563b6e19ed823a78272b954da967a87476
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 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FUNCTIONAL_BIND_FRONT_H
11 #define _LIBCPP___FUNCTIONAL_BIND_FRONT_H
13 #include <__config>
14 #include <__functional/invoke.h>
15 #include <__functional/perfect_forward.h>
16 #include <__type_traits/conjunction.h>
17 #include <__type_traits/decay.h>
18 #include <__type_traits/enable_if.h>
19 #include <__type_traits/is_constructible.h>
20 #include <__type_traits/is_move_constructible.h>
21 #include <__utility/forward.h>
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
25 #endif
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 #if _LIBCPP_STD_VER >= 20
31 struct __bind_front_op {
32 template <class ..._Args>
33 _LIBCPP_HIDE_FROM_ABI
34 constexpr auto operator()(_Args&& ...__args) const
35 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
36 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
37 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
40 template <class _Fn, class ..._BoundArgs>
41 struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
42 using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward;
45 template <class _Fn, class... _Args>
46 requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> &&
47 (is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...)
48 _LIBCPP_HIDE_FROM_ABI
49 constexpr auto bind_front(_Fn&& __f, _Args&&... __args) {
50 return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
53 #endif // _LIBCPP_STD_VER >= 20
55 _LIBCPP_END_NAMESPACE_STD
57 #endif // _LIBCPP___FUNCTIONAL_BIND_FRONT_H