1 // Copyright (c) 2020 Andrey Semashev
3 // Distributed under the Boost Software License, Version 1.0.
4 // See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_ATOMIC_TESTS_ALIGNED_OBJECT_HPP_INCLUDED_
8 #define BOOST_ATOMIC_TESTS_ALIGNED_OBJECT_HPP_INCLUDED_
12 #include <boost/config.hpp>
13 #include <boost/cstdint.hpp>
15 //! A wrapper that creates an object that has at least the specified alignment
16 template< typename T, std::size_t Alignment >
21 unsigned char m_storage[Alignment + sizeof(T)];
26 m_p = new (get_aligned_storage()) T;
29 explicit aligned_object(T const& value)
31 m_p = new (get_aligned_storage()) T(value);
34 ~aligned_object() BOOST_NOEXCEPT
39 T& get() const BOOST_NOEXCEPT
44 BOOST_DELETED_FUNCTION(aligned_object(aligned_object const&))
45 BOOST_DELETED_FUNCTION(aligned_object& operator= (aligned_object const&))
48 unsigned char* get_aligned_storage()
50 #if defined(BOOST_HAS_INTPTR_T)
51 typedef boost::uintptr_t uintptr_type;
53 typedef std::size_t uintptr_type;
55 uintptr_type p = (uintptr_type)(unsigned char*)m_storage;
56 p = (p + (uintptr_type)(Alignment - 1u)) & ~(uintptr_type)(Alignment - 1u);
57 return (unsigned char*)p;
61 #endif // BOOST_ATOMIC_TESTS_ALIGNED_OBJECT_HPP_INCLUDED_