diff --git a/bind.html b/bind.html index ae0064a..dee6dd6 100644 --- a/bind.html +++ b/bind.html @@ -7,7 +7,7 @@
boost::mem_fn is a generalization of the standard functions @@ -41,6 +53,55 @@ object can take a pointer, a reference, or a smart pointer to an object instance as its first argument.
++The purpose of mem_fn is twofold. First, it allows users to invoke a +member function on a container with the familiar +
+ ++ std::for_each(v.begin(), v.end(), boost::mem_fn(&Shape::draw)); ++ +
+syntax, even when the container stores smart pointers. +
+ ++Second, it can be used as a building block by library developers that want +to treat a pointer to member function as a function object. A library might +define an enhanced for_each algorithm with an overload of the form: +
+ ++template<class It, class R> void for_each(It first, It last, R (*pmf) ()) +{ + std::for_each(first, last, boost::mem_fn(pmf)); +} ++ +
+that will allow the convenient syntax: +
+ ++ for_each(v.begin(), v.end(), &Shape::draw); ++ +
+When documenting the feature, the library author will simply state: +
+ ++Effects: equivalent to std::for_each(first, last, boost::mem_fn(pmf)); +
+ ++where boost::mem_fn can be a link to this page. See +the documentation of bind for an example. +
+mem_fn takes one argument, a pointer to a member function, and returns a function object suitable for use with standard or user-defined @@ -105,9 +166,37 @@ All function objects returned by mem_fn expose a result_type typedef that represents the return type of the member function.
-+Yes. For simple uses, mem_fn provides additional functionality that +the standard adaptors do not. Complicated expressions that use std::bind1st, +std::bind2nd or Boost.Compose +along with the standard adaptors can be rewritten using +boost::bind that automatically takes advantage of +mem_fn. +
+ ++No, unless you have good reasons to do so. mem_fn is not 100% compatible +with the standard adaptors, although it comes pretty close. In particular, +mem_fn does not return objects of type +std::[const_]mem_fun[1][_ref]_t, as the standard adaptors do, and it is +not possible to fully describe the type of the first argument using the standard +argument_type and first_argument_type nested typedefs. Libraries +that need adaptable function objects in order to function might not like +mem_fn. +
+ +namespace boost @@ -134,7 +223,7 @@ template<class R, class T, class A1, class A2> implementation-defined-6 }-
All implementation-defined-N types mentioned in the Synopsis are @@ -145,7 +234,7 @@ the return type of the member function pointer passed as an argument to mem_f (R in the Synopsis.)
-This implementation supports member functions with up to eight arguments. @@ -241,7 +348,7 @@ This is not an inherent limitation of the design, but an implementation detail.
-Some platforms allow several types of member functions that differ by their @@ -270,7 +377,7 @@ indirectly, <boost/mem_fn.hpp>.
-Rene Jager's initial suggestion of using traits classes to make