Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2004-03-09 17:26:21

On Tue, Mar 09, 2004 at 05:00:33PM +0200, Peter Dimov wrote:
> What do you think this expression should do:
> bind(f, _1) == bind(g, _1)
> Currently, boost::bind returns f == g when f and g are of the same type, and
> fails at compile type otherwise (this is the equality comparison feature
> Doug requested).
> lambda::bind returns lambda(x) { return f(x) == g(x) }.
> It is clear that a future boost::bind that has limited lambda support would
> be even more problematic (as would be a future equality comparable
> boost.lambda). In that case, the expression will always compile, but do
> something different depending on whether f and g are of the same type.

In my opinion,
   lambda(x) { return f(x) == g(x) }.
is best. Whenever I see a placeholder, I expect the whole expression
(modulo operator precedence and "constant(foo)" issues) to get
lambda-ized, and thus I expect operator== to create a lambda
expression. (I dunno if this is the 'right' expectation to have, given
the way the libraries work now, but I think it is a reasonable/simple
'ideal' expectation.)

More generally, I think it's not a good idea to try to create "function
equality" with operator==. I didn't participate in any of the earlier
discussions, but I think that if you want to register/unregister
function objects with an event handler, for instance, you should use a
separate "handle" object to keep track of "function object identity".
(The whole idea of "f==g" being meaningful for two functions is a little
bit fishy to me, but this is probably more of a personal bias than
anything I can defend objectively.)

-Brian McNamara (lorgon_at_[hidden])

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