Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:28

0001 /*
0002 Copyright (C) 2002 Brad King (brad.king@kitware.com)
0003                    Douglas Gregor (gregod@cs.rpi.edu)
0004 
0005 Copyright (C) 2002, 2008, 2013 Peter Dimov
0006 
0007 Copyright (C) 2017 Glen Joseph Fernandes (glenjofe@gmail.com)
0008 
0009 Distributed under the Boost Software License, Version 1.0.
0010 (See accompanying file LICENSE_1_0.txt or copy at
0011 http://www.boost.org/LICENSE_1_0.txt)
0012 */
0013 
0014 #ifndef BOOST_CORE_ADDRESSOF_HPP
0015 #define BOOST_CORE_ADDRESSOF_HPP
0016 
0017 #include <boost/config.hpp>
0018 
0019 #if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215
0020 #define BOOST_CORE_HAS_BUILTIN_ADDRESSOF
0021 #elif defined(BOOST_GCC) && BOOST_GCC >= 70000
0022 #define BOOST_CORE_HAS_BUILTIN_ADDRESSOF
0023 #elif defined(__has_builtin)
0024 #if __has_builtin(__builtin_addressof)
0025 #define BOOST_CORE_HAS_BUILTIN_ADDRESSOF
0026 #endif
0027 #endif
0028 
0029 #if defined(BOOST_CORE_HAS_BUILTIN_ADDRESSOF)
0030 #if defined(BOOST_NO_CXX11_CONSTEXPR)
0031 #define BOOST_CORE_NO_CONSTEXPR_ADDRESSOF
0032 #endif
0033 
0034 namespace boost {
0035 
0036 template<class T>
0037 BOOST_CONSTEXPR inline T*
0038 addressof(T& o) BOOST_NOEXCEPT
0039 {
0040     return __builtin_addressof(o);
0041 }
0042 
0043 } /* boost */
0044 #else
0045 #include <boost/config/workaround.hpp>
0046 #include <cstddef>
0047 
0048 namespace boost {
0049 namespace detail {
0050 
0051 template<class T>
0052 class addrof_ref {
0053 public:
0054     BOOST_FORCEINLINE addrof_ref(T& o) BOOST_NOEXCEPT
0055         : o_(o) { }
0056     BOOST_FORCEINLINE operator T&() const BOOST_NOEXCEPT {
0057         return o_;
0058     }
0059 private:
0060     addrof_ref& operator=(const addrof_ref&);
0061     T& o_;
0062 };
0063 
0064 template<class T>
0065 struct addrof {
0066     static BOOST_FORCEINLINE T* get(T& o, long) BOOST_NOEXCEPT {
0067         return reinterpret_cast<T*>(&
0068             const_cast<char&>(reinterpret_cast<const volatile char&>(o)));
0069     }
0070     static BOOST_FORCEINLINE T* get(T* p, int) BOOST_NOEXCEPT {
0071         return p;
0072     }
0073 };
0074 
0075 #if !defined(BOOST_NO_CXX11_NULLPTR)
0076 #if !defined(BOOST_NO_CXX11_DECLTYPE) && \
0077     (defined(__INTEL_COMPILER) || \
0078         (defined(__clang__) && !defined(_LIBCPP_VERSION)))
0079 typedef decltype(nullptr) addrof_null_t;
0080 #else
0081 typedef std::nullptr_t addrof_null_t;
0082 #endif
0083 
0084 template<>
0085 struct addrof<addrof_null_t> {
0086     typedef addrof_null_t type;
0087     static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT {
0088         return &o;
0089     }
0090 };
0091 
0092 template<>
0093 struct addrof<const addrof_null_t> {
0094     typedef const addrof_null_t type;
0095     static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT {
0096         return &o;
0097     }
0098 };
0099 
0100 template<>
0101 struct addrof<volatile addrof_null_t> {
0102     typedef volatile addrof_null_t type;
0103     static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT {
0104         return &o;
0105     }
0106 };
0107 
0108 template<>
0109 struct addrof<const volatile addrof_null_t> {
0110     typedef const volatile addrof_null_t type;
0111     static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT {
0112         return &o;
0113     }
0114 };
0115 #endif
0116 
0117 } /* detail */
0118 
0119 #if defined(BOOST_NO_CXX11_SFINAE_EXPR) || \
0120     defined(BOOST_NO_CXX11_CONSTEXPR) || \
0121     defined(BOOST_NO_CXX11_DECLTYPE)
0122 #define BOOST_CORE_NO_CONSTEXPR_ADDRESSOF
0123 
0124 template<class T>
0125 BOOST_FORCEINLINE T*
0126 addressof(T& o) BOOST_NOEXCEPT
0127 {
0128 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x610)) || \
0129     BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5120)
0130     return boost::detail::addrof<T>::get(o, 0);
0131 #else
0132     return boost::detail::addrof<T>::get(boost::detail::addrof_ref<T>(o), 0);
0133 #endif
0134 }
0135 
0136 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
0137 namespace detail {
0138 
0139 template<class T>
0140 struct addrof_result {
0141     typedef T* type;
0142 };
0143 
0144 } /* detail */
0145 
0146 template<class T, std::size_t N>
0147 BOOST_FORCEINLINE typename boost::detail::addrof_result<T[N]>::type
0148 addressof(T (&o)[N]) BOOST_NOEXCEPT
0149 {
0150     return &o;
0151 }
0152 #endif
0153 
0154 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0155 template<class T, std::size_t N>
0156 BOOST_FORCEINLINE
0157 T (*addressof(T (&o)[N]) BOOST_NOEXCEPT)[N]
0158 {
0159    return reinterpret_cast<T(*)[N]>(&o);
0160 }
0161 
0162 template<class T, std::size_t N>
0163 BOOST_FORCEINLINE
0164 const T (*addressof(const T (&o)[N]) BOOST_NOEXCEPT)[N]
0165 {
0166    return reinterpret_cast<const T(*)[N]>(&o);
0167 }
0168 #endif
0169 #else
0170 namespace detail {
0171 
0172 template<class T>
0173 T addrof_declval() BOOST_NOEXCEPT;
0174 
0175 template<class>
0176 struct addrof_void {
0177     typedef void type;
0178 };
0179 
0180 template<class T, class E = void>
0181 struct addrof_member_operator {
0182     static constexpr bool value = false;
0183 };
0184 
0185 template<class T>
0186 struct addrof_member_operator<T, typename
0187     addrof_void<decltype(addrof_declval<T&>().operator&())>::type> {
0188     static constexpr bool value = true;
0189 };
0190 
0191 #if BOOST_WORKAROUND(BOOST_INTEL, < 1600)
0192 struct addrof_addressable { };
0193 
0194 addrof_addressable*
0195 operator&(addrof_addressable&) BOOST_NOEXCEPT;
0196 #endif
0197 
0198 template<class T, class E = void>
0199 struct addrof_non_member_operator {
0200     static constexpr bool value = false;
0201 };
0202 
0203 template<class T>
0204 struct addrof_non_member_operator<T, typename
0205     addrof_void<decltype(operator&(addrof_declval<T&>()))>::type> {
0206     static constexpr bool value = true;
0207 };
0208 
0209 template<class T, class E = void>
0210 struct addrof_expression {
0211     static constexpr bool value = false;
0212 };
0213 
0214 template<class T>
0215 struct addrof_expression<T,
0216     typename addrof_void<decltype(&addrof_declval<T&>())>::type> {
0217     static constexpr bool value = true;
0218 };
0219 
0220 template<class T>
0221 struct addrof_is_constexpr {
0222     static constexpr bool value = addrof_expression<T>::value &&
0223         !addrof_member_operator<T>::value &&
0224         !addrof_non_member_operator<T>::value;
0225 };
0226 
0227 template<bool E, class T>
0228 struct addrof_if { };
0229 
0230 template<class T>
0231 struct addrof_if<true, T> {
0232     typedef T* type;
0233 };
0234 
0235 template<class T>
0236 BOOST_FORCEINLINE
0237 typename addrof_if<!addrof_is_constexpr<T>::value, T>::type
0238 addressof(T& o) BOOST_NOEXCEPT
0239 {
0240     return addrof<T>::get(addrof_ref<T>(o), 0);
0241 }
0242 
0243 template<class T>
0244 constexpr BOOST_FORCEINLINE
0245 typename addrof_if<addrof_is_constexpr<T>::value, T>::type
0246 addressof(T& o) BOOST_NOEXCEPT
0247 {
0248     return &o;
0249 }
0250 
0251 } /* detail */
0252 
0253 template<class T>
0254 constexpr BOOST_FORCEINLINE T*
0255 addressof(T& o) BOOST_NOEXCEPT
0256 {
0257     return boost::detail::addressof(o);
0258 }
0259 #endif
0260 
0261 } /* boost */
0262 #endif
0263 
0264 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
0265     !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
0266 namespace boost {
0267 
0268 template<class T>
0269 const T* addressof(const T&&) = delete;
0270 
0271 } /* boost */
0272 #endif
0273 
0274 #endif