std::mem_fn (3) - Linux Manuals
std::mem_fn: std::mem_fn
NAME
Synopsis
Defined in header <functional>
template< class M, class T > (since C++11)
/*unspecified*/ mem_fn(M T::* pm); (until C++17)
template< class M, class T > (since C++17)
/*unspecified*/ mem_fn(M T::* pm) noexcept;
Function template std::mem_fn generates wrapper objects for pointers to members, which can store, copy, and invoke a pointer to member. Both references and pointers (including smart pointers) to an object can be used when invoking a std::mem_fn.
Parameters
pm - pointer to member that will be wrapped
Return value
std::mem_fn returns a call wrapper of unspecified type that has the following members:
std::mem_fn Return type
Member types
type definition (until C++20)
result_type(deprecated in C++17) the return type of pm if pm is a pointer to member function, not defined for pointer to member object
argument_type(deprecated in C++17) T*, possibly cv-qualified, if pm is a pointer to member function taking no arguments
first_argument_type(deprecated in C++17) T* if pm is a pointer to member function taking one argument
second_argument_type(deprecated in C++17) T1 if pm is a pointer to member function taking one argument of type T1
Member function
template<class... Args>
/* see below */ operator()(Args&&... args);
Let fn be the call wrapper returned by a call to std::mem_fn with a pointer to member pm. Then the expression fn(t, a2, ..., aN) is equivalent to INVOKE(pm, t, a2, ..., aN), where INVOKE is the operation defined in Callable. (Thus, the return type of operator() is std::result_of<decltype(pm)(Args&&...)>::type.)
Each argument in args is perfectly forwarded, as if by std::forward<Args>(args)....
Example
Use mem_fn to store and execute a member function and a member object:
// Run this code
Output:
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG_2048 C++11 unnecessary overloads provided removed
See also
function wraps callable object of any type with specified function call signature
(C++11)
bind binds one or more arguments to a function object
(C++11)