123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #ifndef BOOST_ALIGNED_STORAGE_HPP
- #define BOOST_ALIGNED_STORAGE_HPP
- #include <cstddef> // for std::size_t
- #include "boost/config.hpp"
- #include "boost/detail/workaround.hpp"
- #include "boost/type_traits/alignment_of.hpp"
- #include "boost/type_traits/type_with_alignment.hpp"
- #include "boost/type_traits/is_pod.hpp"
- #include "boost/mpl/eval_if.hpp"
- #include "boost/mpl/identity.hpp"
- #include "boost/type_traits/detail/bool_trait_def.hpp"
- namespace boost {
- namespace detail { namespace aligned_storage {
- BOOST_STATIC_CONSTANT(
- std::size_t
- , alignment_of_max_align = ::boost::alignment_of<max_align>::value
- );
- template <
- std::size_t size_
- , std::size_t alignment_
- >
- struct aligned_storage_imp
- {
- union data_t
- {
- char buf[size_];
- typename mpl::eval_if_c<
- alignment_ == std::size_t(-1)
- , mpl::identity<detail::max_align>
- , type_with_alignment<alignment_>
- >::type align_;
- } data_;
- void* address() const { return const_cast<aligned_storage_imp*>(this); }
- };
- template< std::size_t alignment_ >
- struct aligned_storage_imp<0u,alignment_>
- {
-
- void* address() const { return 0; }
- };
- }}
- template <
- std::size_t size_
- , std::size_t alignment_ = std::size_t(-1)
- >
- class aligned_storage :
- #ifndef __BORLANDC__
- private
- #else
- public
- #endif
- detail::aligned_storage::aligned_storage_imp<size_, alignment_>
- {
-
- public:
- typedef detail::aligned_storage::aligned_storage_imp<size_, alignment_> type;
- BOOST_STATIC_CONSTANT(
- std::size_t
- , size = size_
- );
- BOOST_STATIC_CONSTANT(
- std::size_t
- , alignment = (
- alignment_ == std::size_t(-1)
- ? ::boost::detail::aligned_storage::alignment_of_max_align
- : alignment_
- )
- );
- #if defined(__GNUC__) &&\
- (__GNUC__ > 3) ||\
- (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 ||\
- (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ >=3)))
- private:
- aligned_storage(const aligned_storage&);
- aligned_storage& operator=(const aligned_storage&);
- #else
- public:
- aligned_storage(const aligned_storage&);
- aligned_storage& operator=(const aligned_storage&);
- #endif
- public:
- aligned_storage()
- {
- }
- ~aligned_storage()
- {
- }
- public:
- void* address()
- {
- return static_cast<type*>(this)->address();
- }
- #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- const void* address() const
- {
- return static_cast<const type*>(this)->address();
- }
- #else
- const void* address() const;
- #endif
- };
- #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
- template <std::size_t S, std::size_t A>
- const void* aligned_storage<S,A>::address() const
- {
- return const_cast< aligned_storage<S,A>* >(this)->address();
- }
- #endif
- #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- template <std::size_t size_, std::size_t alignment_>
- struct is_pod<boost::detail::aligned_storage::aligned_storage_imp<size_,alignment_> >
- BOOST_TT_AUX_BOOL_C_BASE(true)
- {
- BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(true)
- };
- #endif
- }
- #include "boost/type_traits/detail/bool_trait_undef.hpp"
- #endif
|