A simple question involving boost.function and boost.lambda
Greetings,
I would like to crate a lambda expression that simply executes two functions sequentially. I have:
using namespace boost;
using namespace boost::lambda;
function0<void> func1 = cout << constant('1');
function0<void> func2 = cout << constant('2');
I have tried:
function0<void> funcs = (func1, func2);
but this seems to execute only one of the two functions when it is called.
I have also tried:
function0<void> funcs = (_1(), _2())(func1, func2);
but my compiler (GCC 3.3 under darwin) barfs it up, with error messages:
----------
main.cpp: In function `int main(int, char**)':
main.cpp:58: error: no match for call to `(boost::tuples::null_type) (
boost::function0
I have tried: function0<void> funcs = (func1, func2); but this seems to execute only one of the two functions when it is called.
Here no lambda expression is involved. It is equivalent to "funcs = func2;".
I have also tried: function0<void> funcs = (_1(), _2())(func1, func2);
Mhm, don't know whether this should work. However, the following does: function0<void> funcs = ( bind<void>(func1), bind<void>(func2) ); You just delay the call to the function objects, as you would do with a function. Wolfgang Meyer
participants (2)
-
gredner@bu.edu
-
Wolfgang Meyer