Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2006-10-05 08:37:45


On Oct 5, 2006, at 8:12 AM, Johan Torp wrote:

> Operator , (nullary composition) does not seem work between
> boost::function and boost::lambda.
> Is this a bug? Is there any way to work around this?
>
> void foo() { std::cout << "foo"; }
>
> boost::function<void()> f(boost::lambda::bind(&foo));
> (f,f)(); // Outputs foo

Okay, so here we're getting the built-in ',' operator, and "f, f" has
no effect other than to give "f" back.

> (boost::lambda::bind(&foo),f)(); // Outputs foo

Doesn't this say: "call foo(), then return f as a value" ?

> (f,boost::lambda::bind(&foo))(); // Outputs foo

Again, I think we're getting the built-in ',' operator, and the "f"
at the beginning has no effect. If the "f" were instead
"boost::lambda::bind(f)", then it should do as you expect.

> (boost::lambda::bind(&foo), boost::lambda::bind(&foo))(); //
> Outputs foofoo

This is definitely what I'd expect.

Should the ',' operator in the Lambda library work for all function
objects, or just lambda's function objects? I'm not really sure, but
we can't detect "all" function objects safely. We could patch up ","
to also work with boost::function, but I'm not sure if that's the way
to go.

In other words, I really can't tell if this is a bug or a feature :)

        Doug


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