134 lines
6.5 KiB
HTML
134 lines
6.5 KiB
HTML
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
contributor license agreements. See the NOTICE file distributed
|
|
with this work for additional information regarding copyright
|
|
ownership. The ASF licenses this file to you under the Apache
|
|
License, Version 2.0 (the License); you may not use this file
|
|
except in compliance with the License. You may obtain a copy of
|
|
the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
implied. See the License for the specific language governing
|
|
permissions and limitations under the License.
|
|
|
|
Copyright 1999-2007 Rogue Wave Software, Inc.
|
|
-->
|
|
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>mem_fun, mem_fun_ref</TITLE>
|
|
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
|
|
<BODY BGCOLOR=#FFFFFF>
|
|
<A HREF="max-element.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="memory-h.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library Reference Guide</B></DIV>
|
|
<H2>mem_fun, mem_fun_ref</H2>
|
|
<P><B>Library:</B> <A HREF="2-4.html">General utilities</A></P>
|
|
|
|
<PRE><HR><B><I>Does not inherit</I></B><HR></PRE>
|
|
|
|
<UL>
|
|
<LI><A HREF="#sec1">Local Index</A></LI>
|
|
<LI><A HREF="#sec2">Summary</A></LI>
|
|
<LI><A HREF="#sec3">Synopsis</A></LI>
|
|
<LI><A HREF="#sec4">Description</A></LI>
|
|
<LI><A HREF="#sec5">Example</A></LI>
|
|
<LI><A HREF="#sec6">See Also</A></LI>
|
|
<LI><A HREF="#sec7">Standards Conformance</A></LI>
|
|
</UL>
|
|
<A NAME="sec1"><H3>Local Index</H3></A>
|
|
No Entries
|
|
<A NAME="sec2"><H3>Summary</H3></A>
|
|
<P>Function objects that adapt a pointer to a member function, to take the place of a global function</P>
|
|
<A NAME="sec3"><H3>Synopsis</H3></A>
|
|
|
|
<PRE>#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);
|
|
}
|
|
</PRE>
|
|
<A NAME="sec4"><H3>Description</H3></A>
|
|
<P>The <B><I><A HREF="mem-fun.html">mem_fun</A></I></B> group of templates encapsulates a pointer to a member function. Each category of template (<B><I>mem_fun</I></B> or <B><I><A HREF="mem-fun.html">mem_fun_ref</A></I></B>) includes both a class template and a function template, where the class is distinguished by the addition of <SAMP>_t</SAMP> on the end of the name to identify it as a type. A set of class templates for const member functions exists, each with <SAMP>const_</SAMP> prepended to the name.</P>
|
|
<P>The class's constructor takes a pointer to a member function and uses <SAMP>operator()</SAMP> to forward the call to that member function. The resulting object serves as a global function object for that member function. </P>
|
|
<P>The accompanying function template simplifies the use of this facility by constructing an instance of the class on the fly. </P>
|
|
<P>The library includes zero and one argument adaptors for containers of pointers and containers of references (<SAMP>_ref</SAMP>). This technique can be easily extended to include adaptors for two argument functions, and so on. </P>
|
|
<A NAME="sec5"><H3>Example</H3></A>
|
|
|
|
<UL><PRE>//
|
|
// mem_fun example
|
|
//
|
|
|
|
#include <functional>
|
|
#include <list>
|
|
using namespace std;
|
|
|
|
int main(void)
|
|
{
|
|
int a1[] = {2,1,5,6,4};
|
|
int a2[] = {11,4,67,3,14};
|
|
list<int> s1(a1,a1+5);
|
|
list<int> s2(a2,a2+5);
|
|
|
|
// Build a list of lists
|
|
list<list<int>* > l;
|
|
l.insert(l.begin(),s1);
|
|
l.insert(l.begin(),s2);
|
|
|
|
// Sort each list in the list
|
|
for_each(l.begin(),l.end(),mem_fun(&list<int>::sort));
|
|
}
|
|
</PRE></UL>
|
|
<A NAME="sec6"><H3>See Also</H3></A>
|
|
<P><B><I><A HREF="binary-function.html">binary_function</A></I></B>, <A HREF="functionobjects.html">Function Objects</A>, <B><I><A HREF="pointer-to-unary-function.html">pointer_to_unary_function</A></I></B>, <SAMP><A HREF="ptr-fun.html">ptr_fun()</A></SAMP></P>
|
|
<A NAME="sec7"><H3>Standards Conformance</H3></A>
|
|
<P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 20.3.8</I></P>
|
|
|
|
<BR>
|
|
<HR>
|
|
<A HREF="max-element.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="memory-h.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A>
|
|
|
|
<!-- Google Analytics tracking code -->
|
|
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
|
</script>
|
|
<script type="text/javascript">
|
|
_uacct = "UA-1775151-1";
|
|
urchinTracker();
|
|
</script>
|
|
<!-- end of Google Analytics tracking code -->
|
|
|
|
</BODY>
|
|
</HTML>
|