Boost logo

Boost :

Subject: Re: [boost] boost::variant and "Current Approach: Temporary Heap Backup" vs "An Initial Solution: Double Storage"
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-30 17:58:03


AMDG

Peter Foelsche wrote:
> 1)
> boost::variant and "Current Approach: Temporary Heap Backup" vs "An
> Initial Solution: Double Storage"
> Please provide both solutions. A potential heap allocation may prevent
> certain application areas.

If any of the variant's types have a no-throw default constructor,
then no heap backup is used, because variant can construct
an object of that type if an exception is thrown. In practice,
this means built-in types, or boost::blank.

> 2)
> I also do not understand that exception safety requires that the
> variant is never empty (e.g. empty() returning always false).
> What is the use of calling the constructor (of which type btw?)
> if somebody creates an unintialized variant variable?
> Or: In the following piece of code is the std::string constructor
> being called?
>
> boost::variant<std::string, int> s;

A default constructed variant is initialized to hold an object of the
first of its types.

In Christ,
Steven Watanabe


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