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 ); +
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;