Boost logo

Boost :

From: Edward Diener (eddielee_at_[hidden])
Date: 2004-01-21 00:13:58


Douglas Gregor wrote:
> On the main branch, I've implemented operator== and operator!= for
> Boost.Function (but not in the form you expect).
>
> The semantics for f == g (and g == f) are:
>
> 1) If f is a Boost.Function object and g is EqualityComparable, the
> result is true when f stores a function object of the type of 'g' and
> that object is equal to 'g' (via g's operator==)
> 2) If f is a Boost.Function object and g is the NULL pointer
> constant, the result is true when f is empty
> 3) Otherwise, the program is ill-formed
>
> The semantics for f != g and g != f follow analagously.
>
> #2 has been implemented for a long time. #1 is the new functionality.
> It's _extremely_ important to note that Boost.Function function
> objects are _NOT_ EqualityComparable, i.e., you cannot compare f == f.
>
> Additionally, there is a "target" member function that returns either
> a pointer to the held function object (if the Boost.Function object
> contains a function object of that type) or NULL otherwise. It's
> usage is, e.g.,
>
> struct Foo { int operator(); };
> struct Bar { int operator(); };
> boost::function<int(void)> f, g, h;
> f = Foo();
> h = Bar();
> Foo* fp = f.target<Foo>(); // okay, points to f's Foo
> Foo* gp = g.target<Foo>(); // okay, NULL pointer
> Foo* hp = g.target<Bar>(); // okay, NULL pointer
>
> This implementation is in response to Herb Sutter's desire to
> implement delegates cleanly via Function, with Kevlin Henney's
> realization that function<> need not be implementable for that to
> work.
>
> Check it out in CVS head. Is this good? TR worthy? Bad?

The million dollar question is: if one uses boost::bind as the mechanism of
passing a member function as an underlying function object to
boost::function, will this new functionality somehow let me check if a
particular member function is indeed the one that boost::function holds as
its function object ? Or maybe it needs to be rephrased as: does an instance
of boost::bind allow me to pass its underlying function object to the new
equality operator of boost::function and is this underlying function object
EqualityComparable ?


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