1 //-----------------------------------------------------------------------------
2 // boost aligned_storage.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
6 // Copyright (c) 2002-2003
7 // Eric Friedman, Itay Maman
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_ALIGNED_STORAGE_HPP
14 #define BOOST_ALIGNED_STORAGE_HPP
16 #include <cstddef> // for std::size_t
18 #include "boost/config.hpp"
19 #include "boost/detail/workaround.hpp"
20 #include "boost/type_traits/alignment_of.hpp"
21 #include "boost/type_traits/type_with_alignment.hpp"
22 #include "boost/type_traits/is_pod.hpp"
24 #include "boost/mpl/eval_if.hpp"
25 #include "boost/mpl/identity.hpp"
27 #include "boost/type_traits/detail/bool_trait_def.hpp"
31 namespace detail { namespace aligned_storage {
33 BOOST_STATIC_CONSTANT(
35 , alignment_of_max_align = ::boost::alignment_of<max_align>::value
39 // To be TR1 conforming this must be a POD type:
43 , std::size_t alignment_
45 struct aligned_storage_imp
51 typename ::boost::mpl::eval_if_c<
52 alignment_ == std::size_t(-1)
53 , ::boost::mpl::identity< ::boost::detail::max_align >
54 , ::boost::type_with_alignment<alignment_>
57 void* address() const { return const_cast<aligned_storage_imp*>(this); }
60 template< std::size_t alignment_ >
61 struct aligned_storage_imp<0u,alignment_>
63 /* intentionally empty */
64 void* address() const { return 0; }
67 }} // namespace detail::aligned_storage
71 , std::size_t alignment_ = std::size_t(-1)
73 class aligned_storage :
79 ::boost::detail::aligned_storage::aligned_storage_imp<size_, alignment_>
84 typedef ::boost::detail::aligned_storage::aligned_storage_imp<size_, alignment_> type;
86 BOOST_STATIC_CONSTANT(
90 BOOST_STATIC_CONSTANT(
93 alignment_ == std::size_t(-1)
94 ? ::boost::detail::aligned_storage::alignment_of_max_align
99 private: // noncopyable
101 aligned_storage(const aligned_storage&);
102 aligned_storage& operator=(const aligned_storage&);
118 return static_cast<type*>(this)->address();
121 const void* address() const
123 return static_cast<const type*>(this)->address();
128 // Make sure that is_pod recognises aligned_storage<>::type
129 // as a POD (Note that aligned_storage<> itself is not a POD):
131 template <std::size_t size_, std::size_t alignment_>
132 struct is_pod< ::boost::detail::aligned_storage::aligned_storage_imp<size_,alignment_> >
133 BOOST_TT_AUX_BOOL_C_BASE(true)
135 BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(true)
141 #include "boost/type_traits/detail/bool_trait_undef.hpp"
143 #endif // BOOST_ALIGNED_STORAGE_HPP