Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

mem_fun, mem_fun_ref

Library:  General utilities


Does not inherit

Local Index

No Entries

Summary

Function objects that adapt a pointer to a member function, to take the place of a global function

Synopsis

#include <functional>

namespace std {
  template <class S, class T> class mem_fun_t; 
  template <class S, class T, class A> class mem_fun1_t;
  template <class S, class T> class mem_fun_ref_t; 
  template <class S, class T, class A> class mem_fun1_ref_t;

  template <class S, class T> class const_mem_fun_t; 
  template <class S, class T, class A> class const_mem_fun1_t;
  template <class S, class T> class const_mem_fun_ref_t; 
  template <class S, class T, class A>
  class const_mem_fun1_ref_t;

  template<class S, class T> mem_fun_t<S,T>
  mem_fun(S, (T::*f)());
  template<class S, class T> mem_fun_ref_t<S,T>
  mem_fun_ref(S, (T::*f)());

  template<class S, class T. class A> mem_fun1_t<S,T,A>
  mem_fun(S, (T::*f)(A));
  template<class S, class T, class A> mem_fun1_ref_t<S,T,A>
  mem_fun_ref(S, (T::*f)(A));

  template<class S, class T> const_mem_fun_t<S,T>
  mem_fun(S, (T::*f)() const);
  template<class S, class T> const_mem_fun_ref_t<S,T>
  mem_fun_ref(S, (T::*f)() const);

  template<class S, class T, class A> const_mem_fun1_t<S,T,A>
  mem_fun(S, (T::*f)(A) const);
  template<class S, class T, class A>
  const_mem_fun1_ref_t<S,T,A>
  mem_fun_ref(S, (T::*f)(A) const);
}

Description

The mem_fun group of templates encapsulates a pointer to a member function. Each category of template (mem_fun or mem_fun_ref) includes both a class template and a function template, where the class is distinguished by the addition of _t on the end of the name to identify it as a type. A set of class templates for const member functions exists, each with const_ prepended to the name.

The class's constructor takes a pointer to a member function and uses operator() to forward the call to that member function. The resulting object serves as a global function object for that member function.

The accompanying function template simplifies the use of this facility by constructing an instance of the class on the fly.

The library includes zero and one argument adaptors for containers of pointers and containers of references (_ref). This technique can be easily extended to include adaptors for two argument functions, and so on.

Example

See Also

binary_function, Function Objects, pointer_to_unary_function, ptr_fun()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 20.3.8



Previous fileTop of DocumentContentsIndex pageNext file