bind_front.h 1.9 KB

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