Boost logo

Boost :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2004-01-21 10:06:41


On Wed, 21 Jan 2004, Peter Dimov wrote:
> Douglas Paul Gregor wrote:
> > boost::bind would need to be EqualityComparable for this to work, and
> > at the moment it is not. It's technically trivially to do, we need only
> > convince Peter :)
>
> There are some interesting corner cases.
>
> int a = 1, b = 1;
>
> int f(int x) { return x; }
>
> bind(f, a) == bind<int>(f, a); // true, false, or ill-formed?

True, I think. We could make a case for ignoring the return type
entirely, because bind expressions with equal arguments should produce
function objects that always have the same result type...

> bind(f, 1) == bind(f, 1L); // true, false, or ill-formed?

True. It seems that the types don't matter at all so long as they are
comparable via ==. One could even have a boost::function<> object on one
side and a bind expression equivalent to the one stored in the
boost::function<> object on the other side, and they would compare equal.

> bind(f, ref(a)) == bind(f, ref(b)); // true or false?

Now _that_ is an interesting corner case.

If we say it's "true", I think we're being true to the notion that
reference_wrapper really is like a reference. But, of course, it's obvious
to us that those two function objects won't always give the same results.

If we say it's "false", then reference_wrapper is acting like a hybrid of
a pointer and a reference. However, we'll be completely sure that the two
function objects will always be the same.

I think we should say it's true, and that reference_wrapper is the closest
we can get to a reference. This is consistent with tuples (where the use
of a reference wrapper just turns into a real reference), with function's
new operator== (always does a value comparison).

Users using ref() when they should be passing a pointer beware. There be
dragons that way.

> and the related question whether reference_wrapper needs operator== and if
> so, what are its semantics. However, ...

Whatever we do, I do not want reference_wrapper to have its own
operator==.

        Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk