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_TT_ALIGNED_STORAGE_HPP
14 #define BOOST_TT_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>
23 #include <boost/type_traits/conditional.hpp>
27 namespace detail { namespace aligned_storage {
29 BOOST_STATIC_CONSTANT(
31 , alignment_of_max_align = ::boost::alignment_of<boost::detail::max_align>::value
35 // To be TR1 conforming this must be a POD type:
39 , std::size_t alignment_
41 struct aligned_storage_imp
47 typename ::boost::type_with_alignment<alignment_>::type align_;
49 void* address() const { return const_cast<aligned_storage_imp*>(this); }
51 template <std::size_t size>
52 struct aligned_storage_imp<size, std::size_t(-1)>
57 ::boost::detail::max_align align_;
59 void* address() const { return const_cast<aligned_storage_imp*>(this); }
62 template< std::size_t alignment_ >
63 struct aligned_storage_imp<0u,alignment_>
65 /* intentionally empty */
66 void* address() const { return 0; }
69 }} // namespace detail::aligned_storage
73 , std::size_t alignment_ = std::size_t(-1)
75 class aligned_storage :
81 ::boost::detail::aligned_storage::aligned_storage_imp<size_, alignment_>
86 typedef ::boost::detail::aligned_storage::aligned_storage_imp<size_, alignment_> type;
88 BOOST_STATIC_CONSTANT(
92 BOOST_STATIC_CONSTANT(
95 alignment_ == std::size_t(-1)
96 ? ::boost::detail::aligned_storage::alignment_of_max_align
101 private: // noncopyable
103 aligned_storage(const aligned_storage&);
104 aligned_storage& operator=(const aligned_storage&);
120 return static_cast<type*>(this)->address();
123 const void* address() const
125 return static_cast<const type*>(this)->address();
130 // Make sure that is_pod recognises aligned_storage<>::type
131 // as a POD (Note that aligned_storage<> itself is not a POD):
133 template <std::size_t size_, std::size_t alignment_>
134 struct is_pod< ::boost::detail::aligned_storage::aligned_storage_imp<size_, alignment_> > : public true_type{};
138 #endif // BOOST_ALIGNED_STORAGE_HPP