2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * Copyright (c) 2009 Helge Bahmann
7 * Copyright (c) 2012 Tim Blechmann
8 * Copyright (c) 2013 - 2014 Andrey Semashev
11 * \file atomic/detail/bitwise_cast.hpp
13 * This header defines \c bitwise_cast used to convert between storage and value types
16 #ifndef BOOST_ATOMIC_DETAIL_BITWISE_CAST_HPP_INCLUDED_
17 #define BOOST_ATOMIC_DETAIL_BITWISE_CAST_HPP_INCLUDED_
19 #include <boost/atomic/detail/config.hpp>
20 #if !defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_MEMCPY)
24 #ifdef BOOST_HAS_PRAGMA_ONCE
28 #if defined(BOOST_GCC) && (BOOST_GCC+0) >= 40600
29 #pragma GCC diagnostic push
30 // missing initializer for member var
31 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
38 template< typename T >
39 BOOST_FORCEINLINE T* addressof(T& value) BOOST_NOEXCEPT
41 // Note: The point of using a local struct as the intermediate type instead of char is to avoid gcc warnings
42 // if T is a const volatile char*:
43 // warning: casting 'const volatile char* const' to 'const volatile char&' does not dereference pointer
44 // The local struct makes sure T is not related to the cast target type.
46 return reinterpret_cast< T* >(&const_cast< opaque_type& >(reinterpret_cast< const volatile opaque_type& >(value)));
49 template< typename To, typename From >
50 BOOST_FORCEINLINE To bitwise_cast(From const& from) BOOST_NOEXCEPT
57 BOOST_ATOMIC_DETAIL_MEMCPY
59 atomics::detail::addressof(value.to),
60 atomics::detail::addressof(from),
61 (sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To))
67 } // namespace atomics
70 #if defined(BOOST_GCC) && (BOOST_GCC+0) >= 40600
71 #pragma GCC diagnostic pop
74 #endif // BOOST_ATOMIC_DETAIL_BITWISE_CAST_HPP_INCLUDED_