I want to suspend a void() function that sets a stack variable to true. How can I do this?
bool flag = false;
boost::function<void()> f = ...;
f();
assert(flag);
This is, obviously, toy code that demonstrates the problem. My attempt at this, using bind, was bind<void>(_1 = constant(true), flag);, but this yields a compilation error.
To use
boost::bind, you’d need to make a function that sets a boolean to true, so you can bind to it:However, lambda’s will help here. Lambda’s are like bind, except they make functions too, so keep your code localized (no need for some external function). You’d do something like this:
Same idea, except
bindandmake_truehas been replaced with a lambda.