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,
making
> 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
opposition
> than I wanted to deal with :)

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

For example, you already have

assert(f);
assert(!f);

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

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);

and

function<void ()> f = 0;

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


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