// (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 { // // typename alignment_alias::type // // is some built-in type with the same alignment requirements of T. // template struct alignment_alias { typedef typename boost::type_with_alignment<::boost::alignment_of::value>::type type ; } ; // // aligned_storage // // This template class can be used to acquire storage for an array of // objects 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 the array of 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->foo(); // ptr->~MyClass() ; // } // template class aligned_storage { union dummy_u { char buffer [ sizeof(T) * Count ] ; typename alignment_alias::type alias ; } dummy ; public : T* address() { return reinterpret_cast(this) ; } } ; } // namespace boost #endif