Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2004-01-20 13:29:09

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 =<Foo>(); // okay, points to f's Foo
Foo* gp =<Foo>(); // okay, NULL pointer
Foo* hp =<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?


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