I am lost, even after looking at the code, of what protect is supposed to do in combination with boost::bind. I read this in the documentation, "Sometimes it is necessary not to evaluate the first argument, but not to evaluate some of the other arguments, even when they are nested bind subexpressions. This can be achieved with the help of another function object, protect, that masks the type so that bind does not recognize and evaluate it. When called, protect simply forwards the argument list to the other function object unmodified. The header boost/bind/protect.hpp contains an implementation of protect. To protect a bind function object from evaluation, use protect(bind(f, ...))." but the grammar, or perhaps the explanation, eludes me. Can anyone explains what it means to protect other arguments so that they are not evaluated in the context of boost::bind, perhaps by a practical example, which I think the doc could use, of what protect actually does ?
In article
I am lost, even after looking at the code, of what protect is supposed to do in combination with boost::bind.
An example where you need to use protect is when you want to call bind and pass the result of a bind to one of its arguments: function<...> f1 = bind(foo, ...); function<...> f2 = bind(bar, ..., f1, ...); The reason for this is that when the result of bind #1 is passed to bind #2, then #1 is evaluated immediately, i.e., foo() is called not from inside bar() as you might desire, but on the second line above where bind is called. However, if you instead call function<...> f2 = bind(bar, ..., protect(f1), ...); then the call to foo() is deferred until the body of bar(). hth meeroh -- If this message helped you, consider buying an item from my wish list: http://web.meeroh.org/wishlist
participants (2)
-
Edward Diener
-
Miro Jurisic