Boost logo

Boost Users :

From: Miro Jurisic (macdev_at_[hidden])
Date: 2004-04-07 00:37:17


In article <c4vs8b$sv$1_at_[hidden]>,
 "Edward Diener" <eddielee_at_[hidden]> wrote:

> 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>

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net