annotate DEPENDENCIES/generic/include/boost/atomic/detail/casts.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 /*
Chris@102 2 * Distributed under the Boost Software License, Version 1.0.
Chris@102 3 * (See accompanying file LICENSE_1_0.txt or copy at
Chris@102 4 * http://www.boost.org/LICENSE_1_0.txt)
Chris@102 5 *
Chris@102 6 * Copyright (c) 2009 Helge Bahmann
Chris@102 7 * Copyright (c) 2012 Tim Blechmann
Chris@102 8 * Copyright (c) 2013 - 2014 Andrey Semashev
Chris@102 9 */
Chris@102 10 /*!
Chris@102 11 * \file atomic/detail/casts.hpp
Chris@102 12 *
Chris@102 13 * This header defines \c union_cast and \c memcpy_cast used to convert between storage and value types
Chris@102 14 */
Chris@102 15
Chris@102 16 #ifndef BOOST_ATOMIC_DETAIL_CASTS_HPP_INCLUDED_
Chris@102 17 #define BOOST_ATOMIC_DETAIL_CASTS_HPP_INCLUDED_
Chris@102 18
Chris@102 19 #include <cstring>
Chris@102 20 #include <boost/atomic/detail/config.hpp>
Chris@102 21
Chris@102 22 #ifdef BOOST_HAS_PRAGMA_ONCE
Chris@102 23 #pragma once
Chris@102 24 #endif
Chris@102 25
Chris@102 26 namespace boost {
Chris@102 27 namespace atomics {
Chris@102 28 namespace detail {
Chris@102 29
Chris@102 30 template< typename To, typename From >
Chris@102 31 BOOST_FORCEINLINE To union_cast(From const& from) BOOST_NOEXCEPT
Chris@102 32 {
Chris@102 33 union
Chris@102 34 {
Chris@102 35 To as_to;
Chris@102 36 From as_from;
Chris@102 37 }
Chris@102 38 caster = {};
Chris@102 39 caster.as_from = from;
Chris@102 40 return caster.as_to;
Chris@102 41 }
Chris@102 42
Chris@102 43 template< typename To, typename From >
Chris@102 44 BOOST_FORCEINLINE To memcpy_cast(From const& from) BOOST_NOEXCEPT
Chris@102 45 {
Chris@102 46 struct
Chris@102 47 {
Chris@102 48 To to;
Chris@102 49 }
Chris@102 50 value = {};
Chris@102 51 std::memcpy
Chris@102 52 (
Chris@102 53 &reinterpret_cast< char& >(value.to),
Chris@102 54 &reinterpret_cast< const char& >(from),
Chris@102 55 (sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To))
Chris@102 56 );
Chris@102 57 return value.to;
Chris@102 58 }
Chris@102 59
Chris@102 60 } // namespace detail
Chris@102 61 } // namespace atomics
Chris@102 62 } // namespace boost
Chris@102 63
Chris@102 64 #endif // BOOST_ATOMIC_DETAIL_CASTS_HPP_INCLUDED_