Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-22 05:44:41


From: "Andreas Huber" <andreas_at_[hidden]>
> Hi Peter
>
> "Foreign" refers to a function object the class of which is not part
> of the boost library (and not an instantiation of a template provided
> by boost). As outlined in my previous post:
[...]
>
> I see that with the design of boost::function ANY function object is
> as good as another. However, that would not be possible if
> boost::function provided equality operations. Please see my reply to
> Doug.

Yes, I see. But even "non-foreign" function objects - such as those
generated by Bind - cannot be compared for equality.

int f(int) { return 5; }

bind(f, 1) == bind(f, 2); // ???

The only reasonable definition for equality for functions is:

Given two functions f(v) and g(v), f == g iff they have the same domain D
and for every v in D f(v) == g(v).

By this definition the above should return true. I don't see an easy way to
implement it.

Also, consider:

struct X {}; // X does not have operator==

int f(X) { return 4; }

bind(f, X()) == bind(f, X()); // ???

Functions simply aren't equality comparable. It'd be much better in the long
run if you accept this fundamental property and decouple the subscriber
identity from the function invoked on publish. IMHO.

--
Peter Dimov
Multi Media Ltd.

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