bind_front.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <__type_traits/conjunction.h>
  15. #include <__type_traits/decay.h>
  16. #include <__type_traits/enable_if.h>
  17. #include <__type_traits/is_constructible.h>
  18. #include <__type_traits/is_move_constructible.h>
  19. #include <__utility/forward.h>
  20. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  21. # pragma GCC system_header
  22. #endif
  23. _LIBCPP_BEGIN_NAMESPACE_STD
  24. #if _LIBCPP_STD_VER >= 20
  25. struct __bind_front_op {
  26. template <class ..._Args>
  27. _LIBCPP_HIDE_FROM_ABI
  28. constexpr auto operator()(_Args&& ...__args) const
  29. noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
  30. -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
  31. { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
  32. };
  33. template <class _Fn, class ..._BoundArgs>
  34. struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> {
  35. using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward;
  36. };
  37. template <class _Fn, class... _Args>
  38. requires is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> &&
  39. (is_constructible_v<decay_t<_Args>, _Args> && ...) && (is_move_constructible_v<decay_t<_Args>> && ...)
  40. _LIBCPP_HIDE_FROM_ABI
  41. constexpr auto bind_front(_Fn&& __f, _Args&&... __args) {
  42. return __bind_front_t<decay_t<_Fn>, decay_t<_Args>...>(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
  43. }
  44. #endif // _LIBCPP_STD_VER >= 20
  45. _LIBCPP_END_NAMESPACE_STD
  46. #endif // _LIBCPP___FUNCTIONAL_BIND_FRONT_H