Boost logo

Boost :

Subject: Re: [boost] aligned_storage in unions
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2010-09-22 06:20:41


On 17/09/2010 16:11, dherring_at_[hidden] wrote:

> 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.

That approach is fundamentally broken as this is not allowed by the
strict aliasing rules of C++.

Every other utility that uses it, such as variant and optional, are
broken too; but they've got no other choice for their implementation,
unfortunately, at least until C++0x.


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