forked from boostorg/bind
Data member support added.
[SVN r14640]
This commit is contained in:
54
mem_fn.html
54
mem_fn.html
@@ -45,7 +45,9 @@
|
||||
<b>boost::mem_fn</b> is a generalization of the standard functions <b>std::mem_fun</b>
|
||||
and <b>std::mem_fun_ref</b>. It supports member function pointers with more
|
||||
than one argument, and the returned function object can take a pointer, a
|
||||
reference, or a smart pointer to an object instance as its first argument.
|
||||
reference, or a smart pointer to an object instance as its first argument. <STRONG>mem_fn</STRONG>
|
||||
also supports pointers to data members by treating them as functions taking no
|
||||
arguments and returning a (const) reference to the member.
|
||||
</p>
|
||||
<p>
|
||||
The purpose of <b>mem_fn</b> is twofold. First, it allows users to invoke a
|
||||
@@ -87,8 +89,8 @@ template<class It, class R, class T> void for_each(It first, It last, R (T
|
||||
documentation of <b>bind</b></a> for an example.
|
||||
</p>
|
||||
<p>
|
||||
<b>mem_fn</b> takes one argument, a pointer to a member function, and returns a
|
||||
function object suitable for use with standard or user-defined algorithms:
|
||||
<b>mem_fn</b> takes one argument, a pointer to a member, and returns a function
|
||||
object suitable for use with standard or user-defined algorithms:
|
||||
</p>
|
||||
<pre>
|
||||
struct X
|
||||
@@ -136,7 +138,8 @@ void k(std::vector<boost::shared_ptr<X> > const & v)
|
||||
</p>
|
||||
<p>
|
||||
All function objects returned by <b>mem_fn</b> expose a <b>result_type</b> typedef
|
||||
that represents the return type of the member function.
|
||||
that represents the return type of the member function. For data members, <STRONG>result_type</STRONG>
|
||||
is defined as a const reference to the type of the member.
|
||||
</p>
|
||||
<h2><a name="FAQ">Frequently Asked Questions</a></h2>
|
||||
<h3><a name="Q1">Can <b>mem_fn</b> be used instead of the standard <b>std::mem_fun[_ref]</b>
|
||||
@@ -176,12 +179,14 @@ void k(std::vector<boost::shared_ptr<X> > const & v)
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template<class T> T * <a href="#get_pointer_1">get_pointer</a> (T * p);
|
||||
template<class T> T * <a href="#get_pointer_1">get_pointer</a>(T * p);
|
||||
|
||||
template<class R, class T> <i>unspecified-1</i> <a href="#mem_fn_1">mem_fn</a>(R (T::*pmf) ());
|
||||
|
||||
template<class R, class T> <i>unspecified-2</i> <a href="#mem_fn_2">mem_fn</a>(R (T::*pmf) () const);
|
||||
|
||||
template<class R, class T> <i>unspecified-2-1</i> <a href="#mem_fn_2_1">mem_fn</a>(R T::*pm);
|
||||
|
||||
template<class R, class T, class A1> <i>unspecified-3</i> <a href="#mem_fn_3">mem_fn</a>(R (T::*pmf) (A1));
|
||||
|
||||
template<class R, class T, class A1> <i>unspecified-4</i> <a href="#mem_fn_4">mem_fn</a>(R (T::*pmf) (A1) const);
|
||||
@@ -196,11 +201,12 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
||||
</pre>
|
||||
<h3><a name="CommonRequirements">Common requirements</a></h3>
|
||||
<p>
|
||||
All <tt><i>unspecified-N</i></tt> types mentioned in the Synopsis
|
||||
are <b>CopyConstructible</b> and <b>Assignable</b>. Their copy constructors and
|
||||
assignment operators do not throw exceptions. <tt><i>unspecified-N</i>::result_type</tt>
|
||||
is defined as the return type of the member function pointer passed as an
|
||||
argument to <b>mem_fn</b> (<b>R</b> in the Synopsis.)
|
||||
All <tt><i>unspecified-N</i></tt> types mentioned in the Synopsis are <b>CopyConstructible</b>
|
||||
and <b>Assignable</b>. Their copy constructors and assignment operators do not
|
||||
throw exceptions. <tt><i>unspecified-N</i>::result_type</tt> is defined as the
|
||||
return type of the member function pointer passed as an argument to <b>mem_fn</b>
|
||||
(<b>R</b> in the Synopsis.) <tt><i>unspecified-2-1</i>::result_type</tt> is
|
||||
defined as <tt>R const &</tt>.
|
||||
</p>
|
||||
<h3><a name="get_pointer">get_pointer</a></h3>
|
||||
<h4><a name="get_pointer_1">template<class T> T * get_pointer(T * p)</a></h4>
|
||||
@@ -213,8 +219,8 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
||||
</p>
|
||||
</blockquote>
|
||||
<h3><a name="mem_fn">mem_fn</a></h3>
|
||||
<h4><a name="mem_fn_1">template<class R, class T> <i>unspecified-1</i>
|
||||
mem_fn(R (T::*pmf) ())</a></h4>
|
||||
<h4><a name="mem_fn_1">template<class R, class T> <i>unspecified-1</i> mem_fn(R
|
||||
(T::*pmf) ())</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
|
||||
@@ -225,8 +231,8 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h4><a name="mem_fn_2">template<class R, class T> <i>unspecified-2</i>
|
||||
mem_fn(R (T::*pmf) () const)</a></h4>
|
||||
<h4><a name="mem_fn_2">template<class R, class T> <i>unspecified-2</i> mem_fn(R
|
||||
(T::*pmf) () const)</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
|
||||
@@ -238,8 +244,20 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h4><a name="mem_fn_3">template<class R, class T, class A1> <i>unspecified-3</i>
|
||||
mem_fn(R (T::*pmf) (A1))</a></h4>
|
||||
<h4><a name="mem_fn_2_1">template<class R, class T> <i>unspecified-2-1</i> mem_fn(R
|
||||
T::*pm)</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
|
||||
is equivalent to <tt>t.*pm</tt> when <i>t</i> is of type <STRONG>T</STRONG> <EM>[const]<STRONG>
|
||||
</STRONG></EM>or derived, <tt>get_pointer(t)->*pm</tt> otherwise.
|
||||
</p>
|
||||
<p>
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h4><a name="mem_fn_3">template<class R, class T, class A1> <i>unspecified-3</i> mem_fn(R
|
||||
(T::*pmf) (A1))</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1)</i></tt>
|
||||
@@ -250,8 +268,8 @@ template<class R, class T, class A1, class A2> <i>unspecified-6</i> <a hre
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h4><a name="mem_fn_4">template<class R, class T, class A1> <i>unspecified-4</i>
|
||||
mem_fn(R (T::*pmf) (A1) const)</a></h4>
|
||||
<h4><a name="mem_fn_4">template<class R, class T, class A1> <i>unspecified-4</i> mem_fn(R
|
||||
(T::*pmf) (A1) const)</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1)</i></tt>
|
||||
|
Reference in New Issue
Block a user