Boost logo

Boost :

Subject: Re: [boost] boost::variant and "Current Approach: Temporary Heap Backup" vs "An Initial Solution: Double Storage"
From: Peter Foelsche (peter_foelsche_at_[hidden])
Date: 2009-09-30 18:23:27


"Steven Watanabe" <watanabesj_at_[hidden]> wrote in message
news:4AC3D46B.4020008_at_providere-consulting.com...
> 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.

This means, my assumptions about exceptions safety of boost::variant may be
wrong.
Is this following code & assertion valid?
I would like if I can assume this.

Thanks
Peter

typedef boost::variant<type1, type2> CVariant;

CVariant s(type1());
try
{ s = type2();
} catch (...)
{ assert(s.which() == boost::mpl::index_of<CVariant::types,
type1>::value);
}


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