.\" ident @(#)mem_fun.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH mem_fun 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2mem_fun\fP, \f2mem_fun1\fP, \f2mem_fun_ref\fP, \f2mem_fun_ref1\fP \ - Function objects that adapt a pointer to a member function, to take the place of a global function. .SH SYNOPSIS .br #include .br template class mem_fun_t; .br template class mem_fun1_t; .br template class mem_fun_ref_t; .br template class mem_fun1_ref_t; .br .br template class const_mem_fun_t; .br template class const_mem_fun1_t; .br template class const_mem_fun_ref_t; .br template .RE .RS 9 class const_mem_fun1_ref_t; .RE .RS 0 .br template mem_fun_t .RE .RS 2 mem_fun(S, (T::*f)()); .RE .RS 0 template mem_fun1_t .RE .RS 2 mem_fun1(S, (T::*f)(A)); .RE .RS 0 template mem_fun_ref_t .RE .RS 2 mem_fun_ref(S, (T::*f)()); .RE .RS 0 template mem_fun1_ref_t .RE .RS 2 mem_fun1_ref(S, (T::*f)(A)); .RE .RS 0 .br template const_mem_fun_t .RE .RS 2 mem_fun(S, (T::*f)() const); .RE .RS 0 template const_mem_fun1_t .RE .RS 2 mem_fun1(S, (T::*f)(A) const); .RE .RS 0 template const_mem_fun_ref_t .RE .RS 2 mem_fun_ref(S, (T::*f)() const); .RE .RS 0 template .RE .RS 2 const_mem_fun1_ref_t .br mem_fun1_ref(S, (T::*f)(A) const); .SH DESCRIPTION The mem_fun_group of templates encapsulates a pointer to a member function. Each category of template (mem_fun, mem_fun1, mem_fun_ref, or mem_fun1_ref) includes both a class template and a function template, where the class is distinguished by the addition of \f2_t\fP on the end of the name to identify it as a type. A set of class templates for const member functions exists, each with \f2const_\fP prepended to the name. The class's constructor takes a pointer to a member function, and uses an \f2operator()\fP to forward the call to that member function. In this way 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 (\f2_ref\fP). This technique can be easily extended to include adaptors for two argument functions, and so on. .SH INTERFACE .RE .RS 0 template class mem_fun_t .RE .RS 10 : public unary_function { .RE .RS 3 public: .RE .RS 5 explicit mem_fun_t(S (T::*p)()); .br S operator()(T* p) const; .RE .RS 0 }; .RE .RS 1 .RE .RS 0 template class mem_fun1_t .RE .RS 10 : public binary_function { .RE .RS 3 public: .RE .RS 5 explicit mem_fun1_t(S (T::*p)(A)); .br S operator()(T* p, A x) const; .RE .RS 0 }; .RE .RS 1 .RE .RS 0 template mem_fun_t .RE .RS 2 mem_fun(S, (T::*f)()); .RE .RS 0 .br template mem_fun1_t .RE .RS 3 mem_fun1(S, (T::*f)(A)); .RE .RS 0 .br template class mem_fun_ref_t .RE .RS 10 : public unary_function { .RE .RS 3 public: .RE .RS 5 explicit mem_fun_ref_t(S (T::*p)()); .br S operator()(T* p) const; .RE .RS 0 }; .RE .RS 1 .RE .RS 0 template class mem_fun1_ref_t .RE .RS 10 : public binary_function { .RE .RS 3 public: .RE .RS 5 explicit mem_fun1_ref_t(S (T::*p)(A)); .br S operator()(T* p, A x) const; .RE .RS 0 }; .br template mem_fun_ref_t .RE .RS 4 mem_fun_ref(S, (T::*f)()); .RE .RS 0 template mem_fun1_ref_t .RE .RS 4 mem_fun1_ref(S, (T::*f)(A)); .RE .RS 0 .br // For const member functions .br .br template class const_mem_fun_t .RE .RS 10 : public unary_function { .RE .RS 3 public: .RE .RS 5 explicit const_mem_fun_t(S (T::*p)() const); .br S operator()(T* p) const; .RE .RS 0 }; .RE .RS 1 .RE .RS 0 template class const_mem_fun1_t .RE .RS 10 : public binary_function { .RE .RS 3 public: .RE .RS 5 explicit const_mem_fun1_t(S (T::*p)(A) const); .br S operator()(T* p, A x) const; .RE .RS 0 }; .RE .RS 1 .RE .RS 0 template const_mem_fun_t .RE .RS 2 mem_fun(S, (T::*f)() const); .RE .RS 0 .br template const_mem_fun1_t .RE .RS 3 mem_fun1(S, (T::*f)(A) const); .RE .RS 0 .br template class const_mem_fun_ref_t .RE .RS 10 : public unary_function { .RE .RS 3 public: .RE .RS 5 explicit const_mem_fun_ref_t(S (T::*p)() const); .br S operator()(T* p) const; .RE .RS 0 }; .RE .RS 1 .RE .RS 0 template .RE .RS 9 class const_mem_fun1_ref_t .RE .RS 10 : public binary_function { .RE .RS 3 public: .RE .RS 5 explicit const_mem_fun1_ref_t(S (T::*p)(A) const); .br S operator()(T* p, A x) const; .RE .RS 0 }; .br template const_mem_fun_ref_t .RE .RS 4 mem_fun_ref(S, (T::*f)() const); .RE .RS 0 template .RE .RS 4 const_mem_fun1_ref_t .br mem_fun1_ref(S, (T::*f)(A) const); .SH EXAMPLE .RE .RS 0 // .br // mem_fun example .br // .br .br #include .br #include .br using namespace std; .br .br int main(void) .br { .RE .RS 1 int a1[] = {2,1,5,6,4}; .br int a2[] = {11,4,67,3,14}; .br list s1(a1,a1+5); .br list s2(a2,a2+5); .RE .RS 0 .RE .RS 2 // Build a list of lists .RE .RS 1 list* > l; .br l.insert(l.begin(),s1); .br l.insert(l.begin(),s2); .RE .RS 0 .RE .RS 2 // Sort each list in the list .RE .RS 1 for_each(l.begin(),l.end(),mem_fun(&list::sort)); .RE .RS 0 } .SH SEE ALSO binary_function, Function_Objects, pointer_to_unary_function, ptr_fun