// (C) 2001, Douglas Gregor. // (C) 2001, Fernando Luis Cacciola Carballal. // // This material is provided "as is", with absolutely no warranty expressed // or implied. Any use is at your own risk. // // Permission to use or copy this software for any purpose is hereby granted // without fee, provided the above notices are retained on all copies. // Permission to modify the code and to distribute modified code is granted, // provided the above notices are retained, and a notice that the code was // modified is included with the above copyright notice. // // #ifndef BOOST_ALIGNED_STORAGE_31AGO2001_HPP #define BOOST_ALIGNED_STORAGE_31AGO2001_HPP #include "boost\type_traits\alignment_traits.hpp" namespace boost { // // alignment_alias::type is a primitive type with the same alignment // requirements of T. // template struct alignment_alias { typedef typename type_with_alignment<::boost::alignment_of::value>::type type ; } ; // // aligned_storage // // This template class can be used to acquire storage for a single // object of type T with the alignment requirement of T. // // An instance of aligned_storage provides a buffer with the base address // suitably aligned and with the required size to allocate an object of type T. // // Instances of aligned_storage can be created on the stack, // therefore, the following is valid: // // void foo() // { // aligned_storage buffer ; // MyClass Value ; // MyClass* ptr = new (buffer.address()) (Value); // ... // ptr->~MyClass() ; // } // template class aligned_storage { union dummy_u { char buffer [ sizeof(T) * Count ] ; typedef alignment_alias::type alias ; } dummy ; public : T* address() { return reinterpret_cast(this) ; } } ; } // namespace boost #endif