Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-04-13 05:35:46

Thorsten Ottosen wrote:
> "Peter Dimov" <pdimov_at_[hidden]> wrote in message
> news:000d01c420a3$e68d6240$1d00a8c0_at_pdimov2...
>> Thorsten Ottosen wrote:
> [snip]
>>>> Why should it not compile?
>>> consider instead
>>> void write_to( string& s )
>>> {
>>> s += " foo";
>>> }
>>> string s = "bar";
>>> bind( write_to, s )();
>>> cout << s; // won't print "bar foo"
>> That's how bind works. All arguments in "bind(write_to, s)" are
>> copied, including 'write_to'. If you make 'write_to' a stateful
>> function object, "bind(write_to, s)()" won't update 'write_to'
>> either.
> But isn't it possible to reject compiling the above example? It's
> really not what
> I would expect people to expect, especially since bind(write,_1)(s)
> differs.

Yes, of course it is possible to reject the example. But I don't want to
reject it. It's useful.

bind(write, _1)(s) is a false analogy. bind is never used like that outside
of toy illustrative examples. You always pass bind(write, _1) to someone
else, and bind(f, a) always makes copies of f and a for lifetime reasons,
regardless of their types.

Consider using lambda::bind, which fails the above example. Isn't
competition wonderful?

Boost list run by bdawes at, gregod at, cpdaniel at, john at