Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2003-09-03 20:31:58

"Joel de Guzman" <djowel_at_[hidden]> escribió en el mensaje news:030a01c3727b$c3524b00$64646464_at_godzilla...
> Andrei Alexandrescu <andrewalex_at_[hidden]> wrote:
> > By the way, could optional<T> use variant<T, SomeInsipidType> as a backend?
> I suggested that before. Now I think that it is not practical.
> It can, but it will not be optimal.
Using variant<> as a backend would be overkill for optional<>
One of the reasons is that variant<> uses the double-storage technique to
achieve higher exception safety than optional<>

> I see it the other way now. I suggest that a partial specialization of
> variant<T, empty> be written that takes advantage of optional<T>
> in its implementation.
This sounds reasonable.

> I think now that the partial specialization of variant<T, empty> will
> satisfy the anti-pointer-like crowd. variant seems to have the right
> interface. Perhaps we were barking up the wrong tree?

BTW, the right variant would be variant<empty,T>, not variant<T,empty>
since variant requires the first type to be default constructible.

A small issue is that variant<>::get() always check and possibly throws,
while optional<>::get() will use BOOST_ASSERT, so that end users can
decide how to deal with uninitialized access.

Fernando Cacciola

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