[aligned storage] support for empty storage

Hi all, Currently the following fails: typedef boost::aligned_storage< 0, 4u > storage; storage s; because this will try to create an empty array. Does anybody have anything against adding the following specialization: template< std::size_t alignment_ > struct aligned_storage_imp<0u,alignment_> { /* intentionally empty */ }; Also, I would like to derive from aligned_storage_imp to get the EBO: template < std::size_t size_ , std::size_t alignment_ = std::size_t(-1)
class aligned_storage : private detail::aligned_storage::aligned_storage_imp<size_, alignment_> { ... } The above changes enable the following program typedef boost::aligned_storage< 0, 4u > storage; struct simple : storage { int i; }; #include <iostream> int main() { std::cout << sizeof(storage) << " " << sizeof(simple); } to output "1 4" instead of "1 8" on gcc. In case your are wondering, then I need this functionality in boost::auto_buffer to get rid of the extra word when the stack-buffer is empty (thus making auto_buffer as small as vector). Comments? -Thorsten

In case your are wondering, then I need this functionality in boost::auto_buffer to get rid of the extra word when the stack-buffer is empty (thus making auto_buffer as small as vector).
Comments?
I haven't looked into this in detail, but what happens on compilers that don't support the EBO? John.

John Maddock skrev:
In case your are wondering, then I need this functionality in boost::auto_buffer to get rid of the extra word when the stack-buffer is empty (thus making auto_buffer as small as vector).
Comments?
I haven't looked into this in detail, but what happens on compilers that don't support the EBO?
Nothing AFAICT. All current uses of aligned_storage has an internal buffer of size at least 1. Having a private data member or inherting privately from a non-empty class should give the same results. For compilers that don't support EBO, the size of an empty aligned_storage will be > 0, but this is also the case when we have an emty data member (at least with gcc). However void* address() const { return this; } probably needs to be modified to return the address of the private base class instead. -Thorsten

John Maddock skrev:
In case your are wondering, then I need this functionality in boost::auto_buffer to get rid of the extra word when the stack-buffer is empty (thus making auto_buffer as small as vector).
Comments?
I haven't looked into this in detail, but what happens on compilers that don't support the EBO?
I have created another test that passes on vc9 ang gcc4.3.2. The test sees if the layout changes depending on a non-empty base class is used or if one uses agregation. I have attached the patch and the new test. Is it ok to commit to trunk? -Thorsten

I have created another test that passes on vc9 ang gcc4.3.2. The test sees if the layout changes depending on a non-empty base class is used or if one uses agregation.
I have attached the patch and the new test.
Is it ok to commit to trunk?
Apologies, I forgot all about this, yes please commit to Trunk, but also keep an eye open for new failures ;-) Cheers, John.
participants (2)
-
John Maddock
-
Thorsten Ottosen