|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-10-08 09:11:29
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 :)
> Actually I have a regression to report. Since function::operator= takes a
> non-const operand, this code now fails:
>
> #include <boost/function.hpp>
>
> typedef boost::function< void * (void * reader) > reader_type;
> typedef std::pair<int, reader_type> mapped_type;
>
> int main()
> {
> mapped_type m;
> m = mapped_type();
> }
>
> as std::pair's implicit assignment operator takes a non-const reference,
> too.
Yeah, that's a problem. Thanks for the testcase. The really annoying part is
that if one writes out the trivial copy assignment operator
pair& operator=(const pair& other)
{
this->first = other.first;
this->second = other.second;
return *this;
}
everything compiles and works properly. Perhaps 12.8/5 is just too strict, and
should be considered a defect?
In any case, back to the whiteboard...
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk