function template
<functional>
std::mem_fntemplate <class Ret, class T> /* unspecified */ mem_fn (Ret T::* pm);
Convert member function to function object
Returns a function object whose functional call invokes the member function pointed by pm.The type of the returned object has the following properties:
fn.*pm
(or (*fn).*pm
if fn is a pointer), forwarding any additional arguments.T*
.T*
, and a member second_argument_type, defined as an alias of the argument taken by pm.The return type is unspecified, but the type returned is a function object class with the properties described above.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// mem_fn example
#include <iostream> // std::cout
#include <functional> // std::mem_fn
struct int_holder {
int value;
int triple() {return value*3;}
};
int main () {
int_holder five {5};
// call member directly:
std::cout << five.triple() << '\n';
// same as above using a mem_fn:
auto triple = std::mem_fn (&int_holder::triple);
std::cout << triple(five) << '\n';
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4