Subject: Re: [boost] [type-traits] aligned_storage in unions
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-09-17 11:47:30
On 09/17/2010 08:37 AM, dherring_at_[hidden] wrote:
> On Fri, 17 Sep 2010, Steven Watanabe wrote:
>> dherring_at_[hidden] wrote:
>>> While C++0x promises to change things (see draft spec section 9.5),
>>> C++ currently does not allow unions to contain members having a
>>> nontrivial constructor, operator=, or destructor. This excludes
>>> std::string, std::complex, structures containing either, etc.
>>> The "standard" workaround is to allocate your own memory and use
>>> manual type casting. Boost::aligned_storage can be used to maintain
>>> proper alignment, but it cannot be placed inside a union due to the
>>> default ctor, dtor, and noncopyable functions. Thus I am forced to
>>> use part of boost::detail.
>> Use boost::aligned_storage<...>::type which should be POD.
> Thanks. Missed that typedef to the detail. Any other comments on the
> approach would be appreciated.
> - Daniel
You can also use boost::type_with_alignment<N>::type within a union to
force a particular alignment.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk