Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / atomic / detail / bitwise_cast.hpp @ 2486

History | View | Annotate | Download (1.2 kB)

1 2486 sjacqu01
/*
2 2486 sjacqu01
 * Distributed under the Boost Software License, Version 1.0.
3 2486 sjacqu01
 * (See accompanying file LICENSE_1_0.txt or copy at
4 2486 sjacqu01
 * http://www.boost.org/LICENSE_1_0.txt)
5 2486 sjacqu01
 *
6 2486 sjacqu01
 * Copyright (c) 2009 Helge Bahmann
7 2486 sjacqu01
 * Copyright (c) 2012 Tim Blechmann
8 2486 sjacqu01
 * Copyright (c) 2013 - 2014 Andrey Semashev
9 2486 sjacqu01
 */
10 2486 sjacqu01
/*!
11 2486 sjacqu01
 * \file   atomic/detail/bitwise_cast.hpp
12 2486 sjacqu01
 *
13 2486 sjacqu01
 * This header defines \c bitwise_cast used to convert between storage and value types
14 2486 sjacqu01
 */
15 2486 sjacqu01
16 2486 sjacqu01
#ifndef BOOST_ATOMIC_DETAIL_BITWISE_CAST_HPP_INCLUDED_
17 2486 sjacqu01
#define BOOST_ATOMIC_DETAIL_BITWISE_CAST_HPP_INCLUDED_
18 2486 sjacqu01
19 2486 sjacqu01
#include <boost/atomic/detail/config.hpp>
20 2486 sjacqu01
#if !defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_MEMCPY)
21 2486 sjacqu01
#include <cstring>
22 2486 sjacqu01
#endif
23 2486 sjacqu01
24 2486 sjacqu01
#ifdef BOOST_HAS_PRAGMA_ONCE
25 2486 sjacqu01
#pragma once
26 2486 sjacqu01
#endif
27 2486 sjacqu01
28 2486 sjacqu01
namespace boost {
29 2486 sjacqu01
namespace atomics {
30 2486 sjacqu01
namespace detail {
31 2486 sjacqu01
32 2486 sjacqu01
template< typename To, typename From >
33 2486 sjacqu01
BOOST_FORCEINLINE To bitwise_cast(From const& from) BOOST_NOEXCEPT
34 2486 sjacqu01
{
35 2486 sjacqu01
    struct
36 2486 sjacqu01
    {
37 2486 sjacqu01
        To to;
38 2486 sjacqu01
    }
39 2486 sjacqu01
    value = {};
40 2486 sjacqu01
    BOOST_ATOMIC_DETAIL_MEMCPY
41 2486 sjacqu01
    (
42 2486 sjacqu01
        &reinterpret_cast< char& >(value.to),
43 2486 sjacqu01
        &reinterpret_cast< const char& >(from),
44 2486 sjacqu01
        (sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To))
45 2486 sjacqu01
    );
46 2486 sjacqu01
    return value.to;
47 2486 sjacqu01
}
48 2486 sjacqu01
49 2486 sjacqu01
} // namespace detail
50 2486 sjacqu01
} // namespace atomics
51 2486 sjacqu01
} // namespace boost
52 2486 sjacqu01
53 2486 sjacqu01
#endif // BOOST_ATOMIC_DETAIL_BITWISE_CAST_HPP_INCLUDED_