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