Blame view

3rdparty/boost_1_81_0/boost/atomic/detail/addressof.hpp 2 KB
63e88f80   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  /*
   * Distributed under the Boost Software License, Version 1.0.
   * (See accompanying file LICENSE_1_0.txt or copy at
   * http://www.boost.org/LICENSE_1_0.txt)
   *
   * Copyright (c) 2018 Andrey Semashev
   */
  /*!
   * \file   atomic/detail/addressof.hpp
   *
   * This header defines \c addressof helper function. It is similar to \c boost::addressof but it is more
   * lightweight and also contains a workaround for some compiler warnings.
   */
  
  #ifndef BOOST_ATOMIC_DETAIL_ADDRESSOF_HPP_INCLUDED_
  #define BOOST_ATOMIC_DETAIL_ADDRESSOF_HPP_INCLUDED_
  
  #include <boost/atomic/detail/config.hpp>
  #include <boost/atomic/detail/header.hpp>
  
  #ifdef BOOST_HAS_PRAGMA_ONCE
  #pragma once
  #endif
  
  // Detection logic is based on boost/core/addressof.hpp
  #if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215
  #define BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF
  #elif defined(BOOST_GCC) && BOOST_GCC >= 70000
  #define BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF
  #elif defined(__has_builtin)
  #if __has_builtin(__builtin_addressof)
  #define BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF
  #endif
  #endif
  
  namespace boost {
  namespace atomics {
  namespace detail {
  
  template< typename T >
  BOOST_FORCEINLINE
  #if defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF)
  BOOST_CONSTEXPR
  #endif
  T* addressof(T& value) BOOST_NOEXCEPT
  {
  #if defined(BOOST_ATOMIC_DETAIL_HAS_BUILTIN_ADDRESSOF)
      return __builtin_addressof(value);
  #else
      // Note: The point of using a local struct as the intermediate type instead of char is to avoid gcc warnings
      // if T is a const volatile char*:
      // warning: casting 'const volatile char* const' to 'const volatile char&' does not dereference pointer
      // The local struct makes sure T is not related to the cast target type.
      struct opaque_type;
      return reinterpret_cast< T* >(&const_cast< opaque_type& >(reinterpret_cast< const volatile opaque_type& >(value)));
  #endif
  }
  
  } // namespace detail
  } // namespace atomics
  } // namespace boost
  
  #include <boost/atomic/detail/footer.hpp>
  
  #endif // BOOST_ATOMIC_DETAIL_ADDRESSOF_HPP_INCLUDED_