Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-10-08 09:21:55

From: "Douglas Gregor" <gregod_at_[hidden]>
> On Tuesday 08 October 2002 07:55 am, Peter Dimov wrote:
> > From: "Douglas Gregor" <gregod_at_[hidden]>
> > > function<int (int x, int y)> f;
> > > f = std::plus<int>();
> > > assert(f != 0); // same as assert(!f.empty())
> > > f = 0; // same as f.clear()
> > > assert(0 == f); // same as assert(f.empty());
> >
> > What is the rationale for the change?
> It gives boost::function nearly identical syntax to function pointers,
> the two interchangeable and smoothing out the learning curve a bit. The
> OO-style '.clear()' and '.empty()' always felt like syntactic warts in a
> class that has such a trivial set of operator overloads. I had originally
> used nil_t/null_t instead of clear(), but that met with a bit more
> than I wanted to deal with :)

I've been considering something along those lines for shared_ptr... how much

For example, you already have


(on some broken asserts you'll likely need assert(f? true: false)

So one might argue that comparisons to zero aren't necessary, esp. since you
can't compare function instances for equality.

On the other hand, you can initialize function pointers with zero, so you
might want to add

function<void ()> f(0);


function<void ()> f = 0;

support. Now should that constructor be implicit? Decisions...

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