]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/atomic/detail/bitwise_fp_cast.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / atomic / detail / bitwise_fp_cast.hpp
CommitLineData
11fdf7f2
TL
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) 2018 Andrey Semashev
7 */
8/*!
9 * \file atomic/detail/bitwise_fp_cast.hpp
10 *
11 * This header defines \c bitwise_fp_cast used to convert between storage and floating point value types
12 */
13
14#ifndef BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_
15#define BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_
16
17#include <cstddef>
18#include <boost/atomic/detail/config.hpp>
19#include <boost/atomic/detail/float_sizes.hpp>
20#include <boost/atomic/detail/bitwise_cast.hpp>
20effc67 21#include <boost/atomic/detail/header.hpp>
11fdf7f2
TL
22
23#ifdef BOOST_HAS_PRAGMA_ONCE
24#pragma once
25#endif
26
27namespace boost {
28namespace atomics {
29namespace detail {
30
31/*!
32 * \brief The type trait returns the size of the value of the specified floating point type
33 *
34 * This size may be less than <tt>sizeof(T)</tt> if the implementation uses padding bytes for a particular FP type. This is
35 * often the case with 80-bit extended double, which is stored in 12 or 16 bytes with padding filled with garbage.
36 */
37template< typename T >
38struct value_sizeof
39{
40 static BOOST_CONSTEXPR_OR_CONST std::size_t value = sizeof(T);
41};
42
43#if defined(BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE)
44template< >
45struct value_sizeof< float >
46{
47 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_FLOAT_VALUE;
48};
49#endif
50
51#if defined(BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE)
52template< >
53struct value_sizeof< double >
54{
55 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_DOUBLE_VALUE;
56};
57#endif
58
59#if defined(BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE)
60template< >
61struct value_sizeof< long double >
62{
63 static BOOST_CONSTEXPR_OR_CONST std::size_t value = BOOST_ATOMIC_DETAIL_SIZEOF_LONG_DOUBLE_VALUE;
64};
65#endif
66
67template< typename T >
68struct value_sizeof< const T > : value_sizeof< T > {};
69
70template< typename T >
71struct value_sizeof< volatile T > : value_sizeof< T > {};
72
73template< typename T >
74struct value_sizeof< const volatile T > : value_sizeof< T > {};
75
76
77template< typename To, typename From >
78BOOST_FORCEINLINE To bitwise_fp_cast(From const& from) BOOST_NOEXCEPT
79{
80 return atomics::detail::bitwise_cast< To, atomics::detail::value_sizeof< From >::value >(from);
81}
82
83} // namespace detail
84} // namespace atomics
85} // namespace boost
86
20effc67
TL
87#include <boost/atomic/detail/footer.hpp>
88
11fdf7f2 89#endif // BOOST_ATOMIC_DETAIL_BITWISE_FP_CAST_HPP_INCLUDED_