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