diff --git a/bind.html b/bind.html index 36ea678..8570bd6 100644 --- a/bind.html +++ b/bind.html @@ -188,6 +188,27 @@ bind(std::less<int>(), _1, 9)(x); // x < 9

[Note: the ability to omit the return type is not available on all compilers.]

+

By default, bind makes a copy of the provided function object. + boost::ref and boost::cref can be used to make it store + a reference to the function object, rather than a copy. This can be useful when + the function object is noncopyable, expensive to copy, or contains state; of + course, in this case the programmer is expected to ensure that the function + object is not destroyed while it's still being used.

+
struct F2
+{
+    int s;
+
+    typedef void result_type;
+    void operator()( int x ) { s += x; }
+};
+
+F2 f2 = { 0 };
+int a[] = { 1, 2, 3 };
+
+std::for_each( a, a+3, bind( ref(f2), _1 ) );
+
+assert( f2.s == 6 );
+

Using bind with pointers to members

Pointers to member functions and pointers to data members are not function objects, because they do not support operator(). For convenience, bind @@ -859,7 +880,7 @@ namespace by Jaakko Järvi;

  • The Lambda Library - (now part of Boost) by Jaakko Järvi and Gary Powell (the successor to the + (now part of Boost) by Jaakko Järvi and Gary Powell (the successor to the Binder Library);
  • Extensions to the STL by Petter @@ -890,7 +911,7 @@ namespace

    Copyright © 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright - 2003-2005 Peter Dimov. Distributed under the Boost Software License, Version + 2003-2008 Peter Dimov. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.