sl@0: //-----------------------------------------------------------------------------
sl@0: // boost aligned_storage.hpp header file
sl@0: // See http://www.boost.org for updates, documentation, and revision history.
sl@0: //-----------------------------------------------------------------------------
sl@0: //
sl@0: // Copyright (c) 2002-2003
sl@0: // Eric Friedman, Itay Maman
sl@0: //
sl@0: // Distributed under the Boost Software License, Version 1.0. (See
sl@0: // accompanying file LICENSE_1_0.txt or copy at
sl@0: // http://www.boost.org/LICENSE_1_0.txt)
sl@0: 
sl@0: #ifndef BOOST_ALIGNED_STORAGE_HPP
sl@0: #define BOOST_ALIGNED_STORAGE_HPP
sl@0: 
sl@0: #include <cstddef> // for std::size_t
sl@0: 
sl@0: #include "boost/config.hpp"
sl@0: #include "boost/detail/workaround.hpp"
sl@0: #include "boost/type_traits/alignment_of.hpp"
sl@0: #include "boost/type_traits/type_with_alignment.hpp"
sl@0: #include "boost/type_traits/is_pod.hpp"
sl@0: 
sl@0: #include "boost/mpl/eval_if.hpp"
sl@0: #include "boost/mpl/identity.hpp"
sl@0: 
sl@0: #include "boost/type_traits/detail/bool_trait_def.hpp"
sl@0: 
sl@0: namespace boost {
sl@0: 
sl@0: namespace detail { namespace aligned_storage {
sl@0: 
sl@0: BOOST_STATIC_CONSTANT(
sl@0:       std::size_t
sl@0:     , alignment_of_max_align = ::boost::alignment_of<max_align>::value
sl@0:     );
sl@0: 
sl@0: //
sl@0: // To be TR1 conforming this must be a POD type:
sl@0: //
sl@0: template <
sl@0:       std::size_t size_
sl@0:     , std::size_t alignment_
sl@0: >
sl@0: struct aligned_storage_imp
sl@0: {
sl@0:     union data_t
sl@0:     {
sl@0:         char buf[size_];
sl@0: 
sl@0:         typename mpl::eval_if_c<
sl@0:               alignment_ == std::size_t(-1)
sl@0:             , mpl::identity<detail::max_align>
sl@0:             , type_with_alignment<alignment_>
sl@0:             >::type align_;
sl@0:     } data_;
sl@0: };
sl@0: 
sl@0: }} // namespace detail::aligned_storage
sl@0: 
sl@0: template <
sl@0:       std::size_t size_
sl@0:     , std::size_t alignment_ = std::size_t(-1)
sl@0: >
sl@0: class aligned_storage
sl@0: {
sl@0: private: // representation
sl@0: 
sl@0:    detail::aligned_storage::aligned_storage_imp<size_, alignment_> data_;
sl@0: 
sl@0: public: // constants
sl@0: 
sl@0:     typedef detail::aligned_storage::aligned_storage_imp<size_, alignment_> type;
sl@0: 
sl@0:     BOOST_STATIC_CONSTANT(
sl@0:           std::size_t
sl@0:         , size = size_
sl@0:         );
sl@0:     BOOST_STATIC_CONSTANT(
sl@0:           std::size_t
sl@0:         , alignment = (
sl@0:               alignment_ == std::size_t(-1)
sl@0:             ? ::boost::detail::aligned_storage::alignment_of_max_align
sl@0:             : alignment_
sl@0:             )
sl@0:         );
sl@0: 
sl@0: #if defined(__GNUC__) &&\
sl@0:     (__GNUC__ >  3) ||\
sl@0:     (__GNUC__ == 3 && (__GNUC_MINOR__ >  2 ||\
sl@0:                       (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ >=3)))
sl@0: 
sl@0: private: // noncopyable
sl@0: 
sl@0:     aligned_storage(const aligned_storage&);
sl@0:     aligned_storage& operator=(const aligned_storage&);
sl@0: 
sl@0: #else // gcc less than 3.2.3
sl@0: 
sl@0: public: // _should_ be noncopyable, but GCC compiler emits error
sl@0: 
sl@0:     aligned_storage(const aligned_storage&);
sl@0:     aligned_storage& operator=(const aligned_storage&);
sl@0: 
sl@0: #endif // gcc < 3.2.3 workaround
sl@0: 
sl@0: public: // structors
sl@0: 
sl@0:     aligned_storage()
sl@0:     {
sl@0:     }
sl@0: 
sl@0:     ~aligned_storage()
sl@0:     {
sl@0:     }
sl@0: 
sl@0: public: // accessors
sl@0: 
sl@0:     void* address()
sl@0:     {
sl@0:         return this;
sl@0:     }
sl@0: 
sl@0: #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
sl@0: 
sl@0:     const void* address() const
sl@0:     {
sl@0:         return this;
sl@0:     }
sl@0: 
sl@0: #else // MSVC6
sl@0: 
sl@0:     const void* address() const;
sl@0: 
sl@0: #endif // MSVC6 workaround
sl@0: 
sl@0: };
sl@0: 
sl@0: #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
sl@0: 
sl@0: // MSVC6 seems not to like inline functions with const void* returns, so we
sl@0: // declare the following here:
sl@0: 
sl@0: template <std::size_t S, std::size_t A>
sl@0: const void* aligned_storage<S,A>::address() const
sl@0: {
sl@0:     return const_cast< aligned_storage<S,A>* >(this)->address();
sl@0: }
sl@0: 
sl@0: #endif // MSVC6 workaround
sl@0: 
sl@0: #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0: //
sl@0: // Make sure that is_pod recognises aligned_storage<>::type
sl@0: // as a POD (Note that aligned_storage<> itself is not a POD):
sl@0: //
sl@0: template <std::size_t size_, std::size_t alignment_>
sl@0: struct is_pod<boost::detail::aligned_storage::aligned_storage_imp<size_,alignment_> >
sl@0:    BOOST_TT_AUX_BOOL_C_BASE(true)
sl@0: { 
sl@0:     BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(true)
sl@0: }; 
sl@0: #endif
sl@0: 
sl@0: 
sl@0: } // namespace boost
sl@0: 
sl@0: #include "boost/type_traits/detail/bool_trait_undef.hpp"
sl@0: 
sl@0: #endif // BOOST_ALIGNED_STORAGE_HPP