1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// See http://www.boost.org/libs/container for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10#ifndef BOOST_MOVE_DETAIL_ADDRESSOF_HPP
11#define BOOST_MOVE_DETAIL_ADDRESSOF_HPP
12
13#ifndef BOOST_CONFIG_HPP
14# include <boost/config.hpp>
15#endif
16
17#if defined(BOOST_HAS_PRAGMA_ONCE)
18# pragma once
19#endif
20
21#include <boost/move/detail/workaround.hpp>
22
23namespace boost {
24namespace move_detail {
25
26#if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215
27#define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
28#elif defined(BOOST_GCC) && BOOST_GCC >= 70000
29#define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
30#elif defined(__has_builtin)
31#if __has_builtin(__builtin_addressof)
32#define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
33#endif
34#endif
35
36#ifdef BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
37
38template<class T>
39BOOST_MOVE_FORCEINLINE T *addressof( T & v ) BOOST_NOEXCEPT
40{
41 return __builtin_addressof(v);
42}
43
44#else //BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
45
46template <typename T>
47BOOST_MOVE_FORCEINLINE T* addressof(T& obj)
48{
49 return static_cast<T*>(
50 static_cast<void*>(
51 const_cast<char*>(
52 &reinterpret_cast<const volatile char&>(obj)
53 )));
54}
55
56#endif //BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
57
58} //namespace move_detail {
59} //namespace boost {
60
61#endif //#ifndef BOOST_MOVE_DETAIL_ADDRESSOF_HPP
62