Statistics
| Revision:

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

History | View | Annotate | Download (1.4 kB)

1
/*
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)
5
 *
6
 * Copyright (c) 2009 Helge Bahmann
7
 * Copyright (c) 2012 Tim Blechmann
8
 * Copyright (c) 2013 - 2014 Andrey Semashev
9
 */
10
/*!
11
 * \file   atomic/detail/casts.hpp
12
 *
13
 * This header defines \c union_cast and \c memcpy_cast used to convert between storage and value types
14
 */
15

    
16
#ifndef BOOST_ATOMIC_DETAIL_CASTS_HPP_INCLUDED_
17
#define BOOST_ATOMIC_DETAIL_CASTS_HPP_INCLUDED_
18

    
19
#include <cstring>
20
#include <boost/atomic/detail/config.hpp>
21

    
22
#ifdef BOOST_HAS_PRAGMA_ONCE
23
#pragma once
24
#endif
25

    
26
namespace boost {
27
namespace atomics {
28
namespace detail {
29

    
30
template< typename To, typename From >
31
BOOST_FORCEINLINE To union_cast(From const& from) BOOST_NOEXCEPT
32
{
33
    union
34
    {
35
        To as_to;
36
        From as_from;
37
    }
38
    caster = {};
39
    caster.as_from = from;
40
    return caster.as_to;
41
}
42

    
43
template< typename To, typename From >
44
BOOST_FORCEINLINE To memcpy_cast(From const& from) BOOST_NOEXCEPT
45
{
46
    struct
47
    {
48
        To to;
49
    }
50
    value = {};
51
    std::memcpy
52
    (
53
        &reinterpret_cast< char& >(value.to),
54
        &reinterpret_cast< const char& >(from),
55
        (sizeof(From) < sizeof(To) ? sizeof(From) : sizeof(To))
56
    );
57
    return value.to;
58
}
59

    
60
} // namespace detail
61
} // namespace atomics
62
} // namespace boost
63

    
64
#endif // BOOST_ATOMIC_DETAIL_CASTS_HPP_INCLUDED_