Boost logo

Boost :

Subject: [boost] static_vector using aligned_storage
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2012-12-12 11:08:12


Hi,

I'm developing R-tree container for Boost.Geometry. To keep it short,
there are containers of Values in leaf nodes. Those containers must have
push_back() functionality. For static-size nodes I'm using a container
based on boost::array. Unfortunately this means that default
constructors of stored Values are called when the container is created.
I'd like not to expect that Values have their default ctor implemented.
I've implemented an alternative container using boost::aligned_storage.
This is just a proof of concept. The code is available here:

https://svn.boost.org/svn/boost/sandbox-branches/geometry/index/tests/static_vector.cpp

I've searched for this kind of container in Boost since I remember that
someone proposed it some time ago but didn't find it anywhere. Is it
released somewhere? Maby as a part of some library?

If not, would you be so kind and see if my solution should work for
any/most popular compiler/platform? I've tested it only on clang.

To be specific, won't there be any problems with the memory aligmnent if
I use this code for storage:

boost::aligned_storage<sizeof(Value) * Capacity> m_storage;

this for access:

*(reinterpret_cast<Value*>(m_storage.address()) + i);

and this for construction

new
(reinterpret_cast<Value*>(m_storage.address()) + i)
Value(value);

Regards,
Adam


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