
I have the following simple test case:
#include

I have the following simple test case: void show(int x) { cout << x << endl; } void twice(function0<void> f) { f(); f(); } int main() { // This works... function
f = bind(show, 0); bind(twice, f)(); // ...but this does not compile. // bind(twice, bind(show, 0))(); return 0; }
You can do a cast:
boost::bind(twice, (boost::function

Steven Watanabe wrote:
AMDG
Yang Zhang wrote:
// ...but this does not compile. // bind(twice, bind(show, 0))();
#include
...
bind(twice, protect(bind(show, 0)))
Thanks, this works. Would anybody be able to explain what just happened? According to: http://www.boost.org/doc/libs/1_37_0/libs/bind/bind.html#nested_binds this is supposed to prevent something from being evaluated, but I can't tell what precisely was going on. I believe my question of understanding also ties into why their `apply` example was necessary.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Yang Zhang http://www.mit.edu/~y_z/

AMDG Yang Zhang wrote:
bind(twice, protect(bind(show, 0)))
Thanks, this works. Would anybody be able to explain what just happened? According to:
bind(twice, bind(show, 0))() is evaluated as twice(show(0)) You want: twice(bind(show, 0)) The protect prevents show from being evaluated immediately by Boost.Bind. In Christ, Steven Watanabe

On Thu, Nov 20, 2008 at 08:28:35AM -0800, Steven Watanabe wrote:
The protect prevents show from being evaluated immediately by Boost.Bind.
In other words, does protect allow "lazy" evaluation? Matthias -- Matthias Vallentin vallentin@icsi.berkeley.edu http://matthias.vallentin.cc
participants (4)
-
Matthias Vallentin
-
Patrick Loney
-
Steven Watanabe
-
Yang Zhang