mem_fn.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_MEM_FN_H
  10. #define _LIBCPP___FUNCTIONAL_MEM_FN_H
  11. #include <__config>
  12. #include <__functional/binary_function.h>
  13. #include <__functional/invoke.h>
  14. #include <__functional/weak_result_type.h>
  15. #include <__utility/forward.h>
  16. #include <type_traits>
  17. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  18. # pragma GCC system_header
  19. #endif
  20. _LIBCPP_BEGIN_NAMESPACE_STD
  21. template <class _Tp>
  22. class __mem_fn : public __weak_result_type<_Tp>
  23. {
  24. public:
  25. // types
  26. typedef _Tp type;
  27. private:
  28. type __f_;
  29. public:
  30. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  31. __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
  32. // invoke
  33. template <class... _ArgTypes>
  34. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  35. typename __invoke_return<type, _ArgTypes...>::type
  36. operator() (_ArgTypes&&... __args) const {
  37. return std::__invoke(__f_, std::forward<_ArgTypes>(__args)...);
  38. }
  39. };
  40. template<class _Rp, class _Tp>
  41. inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  42. __mem_fn<_Rp _Tp::*>
  43. mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
  44. {
  45. return __mem_fn<_Rp _Tp::*>(__pm);
  46. }
  47. _LIBCPP_END_NAMESPACE_STD
  48. #endif // _LIBCPP___FUNCTIONAL_MEM_FN_H