1fe6060f1SDimitry Andric // -*- C++ -*- 2fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 3fe6060f1SDimitry Andric // 4fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7fe6060f1SDimitry Andric // 8fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 9fe6060f1SDimitry Andric 10fe6060f1SDimitry Andric #ifndef _LIBCPP___FUNCTIONAL_BIND_FRONT_H 11fe6060f1SDimitry Andric #define _LIBCPP___FUNCTIONAL_BIND_FRONT_H 12fe6060f1SDimitry Andric 13fe6060f1SDimitry Andric #include <__config> 14fe6060f1SDimitry Andric #include <__functional/invoke.h> 1504eeddc0SDimitry Andric #include <__functional/perfect_forward.h> 1606c3fb27SDimitry Andric #include <__type_traits/conjunction.h> 1706c3fb27SDimitry Andric #include <__type_traits/decay.h> 1806c3fb27SDimitry Andric #include <__type_traits/enable_if.h> 1906c3fb27SDimitry Andric #include <__type_traits/is_constructible.h> 2081ad6265SDimitry Andric #include <__utility/forward.h> 21fe6060f1SDimitry Andric 22fe6060f1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 23fe6060f1SDimitry Andric # pragma GCC system_header 24fe6060f1SDimitry Andric #endif 25fe6060f1SDimitry Andric 26fe6060f1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 27fe6060f1SDimitry Andric 2806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 29fe6060f1SDimitry Andric 30349cc55cSDimitry Andric struct __bind_front_op { 31fe6060f1SDimitry Andric template <class... _Args> 32*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const noexcept( 33*0fca6ea1SDimitry Andric noexcept(std::invoke(std::forward<_Args>(__args)...))) -> decltype(std::invoke(std::forward<_Args>(__args)...)) { 34cb14a3feSDimitry Andric return std::invoke(std::forward<_Args>(__args)...); 35cb14a3feSDimitry Andric } 36fe6060f1SDimitry Andric }; 37fe6060f1SDimitry Andric 38349cc55cSDimitry Andric template <class _Fn, class... _BoundArgs> 39349cc55cSDimitry Andric struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> { 40349cc55cSDimitry Andric using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward; 41349cc55cSDimitry Andric }; 42349cc55cSDimitry Andric 435f757f3fSDimitry Andric template <class _Fn, class... _Args> 445f757f3fSDimitry Andric requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> && 455f757f3fSDimitry Andric (is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...) 46cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr auto bind_front(_Fn&& __f, _Args&&... __args) { 475f757f3fSDimitry Andric return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(std::forward<_Fn>(__f), std::forward<_Args>(__args)...); 48fe6060f1SDimitry Andric } 49fe6060f1SDimitry Andric 5006c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 51fe6060f1SDimitry Andric 52fe6060f1SDimitry Andric _LIBCPP_END_NAMESPACE_STD 53fe6060f1SDimitry Andric 54fe6060f1SDimitry Andric #endif // _LIBCPP___FUNCTIONAL_BIND_FRONT_H 55