A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/functional/mem_fn/ below:

function template

<functional>

std::mem_fn
template <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:



Parameters
pm
Pointer to a member function.

Return value A function object that, when called, calls pm on the object passed as first argument.

The return type is unspecified, but the type returned is a function object class with the properties described above.



Example
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;
}

Output:


Exception safetyNo-throw guarantee: never throws exceptions.

See also
reference_wrapper
Reference wrapper (class template)
bind
Bind function arguments (function template)

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