Boost logo

Boost :

Subject: Re: [boost] [optional] std::tr2::optional
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2011-11-22 04:32:18

> boost::optional can be used for many purposes. One of these (and I had to
> use optional like that) is to make classes that provide RAII-like
> (noncopyable, nonmoveable) usable in contexts where I need to use
> initialization or to release the resource before the end of the scope
> (subject to some runtime condition) -- all that in order to have a
> acquired for as short span of time as possible.
> I would be forced to do that for std::lock_guard if the library did not
> provide a second template std::unique_lock. But not every library
> two interfaces for almost the same thing, and this is arguably an
> unnecessary redundancy for an interface. optional<RAII> as described
> is a generic tool for transforming types that implement 'scoped
> into types that implement 'unique ownership' of a resource.

I think I went too far with this story. Although you can implement a
two-phase initialization and cleanup, you cannot provide a full 'unique
ownership' semantics with boost::optional for 'scoped' types, because there
is no way to implement a move constructor for types that do not support
either a move constructor or swap.


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