Boost logo

Boost :

From: Calum Grant (calum_at_[hidden])
Date: 2005-07-16 11:40:06


Andrey Melnikov wrote:
> David Abrahams wrote:
> > "Calum Grant" <calum_at_[hidden]> writes:
> >>In the absence of Boost, I would probably use a
> std::auto_ptr to store
> >>an optional field, which is, um, a smart pointer. I realize that
> >>Optional is implemented slightly differently.
> >
> >
> > I wouldn't characterize it as a "slight" difference.
> >
> I hate extra dynamic memory allocation even more than I hate extra
> copies, because the former cannot be optimized out and usually takes
> more time than 10 extra copies. Well, pool allocators help a lot
> sometimes, but it's an optimization technology.
>
> I like Boost.Optional because it offers a good way to deal with
> optonality without any extra pointers, memory allocations, special
> "NULL" values or construction or copy operations . I think it's way
> different from the concept of smart pointers.

I completely take your point that Boost.Optional would be drastically
more efficient in many circumstances. But I would also say it could be
less efficient than dynamic memory allocation in a limited number of
cases.

But we're talking about private implementation. From a semantic
perspective, Optional behaves like a smart pointer with a "copy on
assign" policy. Perhaps there would be fewer howls of disapproval if I
called it a smart container, not a smart pointer.

If an implementation improves a smart container/pointer in this
circumstance then that's fanstastic.

Calum


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