[12] | 1 | // Copyright (C) 2002 Brad King (brad.king@kitware.com) |
---|
| 2 | // Douglas Gregor (gregod@cs.rpi.edu) |
---|
| 3 | // Peter Dimov |
---|
| 4 | // |
---|
| 5 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
| 8 | |
---|
| 9 | // For more information, see http://www.boost.org |
---|
| 10 | |
---|
| 11 | #ifndef BOOST_UTILITY_ADDRESSOF_HPP |
---|
| 12 | # define BOOST_UTILITY_ADDRESSOF_HPP |
---|
| 13 | |
---|
| 14 | # include <boost/config.hpp> |
---|
| 15 | # include <boost/detail/workaround.hpp> |
---|
| 16 | |
---|
| 17 | namespace boost { |
---|
| 18 | |
---|
| 19 | // Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov) |
---|
| 20 | |
---|
| 21 | // VC7 strips const from nested classes unless we add indirection here |
---|
| 22 | # if BOOST_WORKAROUND(BOOST_MSVC, == 1300) |
---|
| 23 | |
---|
| 24 | template<class T> struct _addp |
---|
| 25 | { |
---|
| 26 | typedef T * type; |
---|
| 27 | }; |
---|
| 28 | |
---|
| 29 | template <typename T> typename _addp<T>::type |
---|
| 30 | |
---|
| 31 | # else |
---|
| 32 | template <typename T> T* |
---|
| 33 | # endif |
---|
| 34 | addressof(T& v) |
---|
| 35 | { |
---|
| 36 | return reinterpret_cast<T*>( |
---|
| 37 | &const_cast<char&>(reinterpret_cast<const volatile char &>(v))); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | // Borland doesn't like casting an array reference to a char reference |
---|
| 41 | // but these overloads work around the problem. |
---|
| 42 | # if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
---|
| 43 | template<typename T,std::size_t N> |
---|
| 44 | T (*addressof(T (&t)[N]))[N] |
---|
| 45 | { |
---|
| 46 | return reinterpret_cast<T(*)[N]>(&t); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | template<typename T,std::size_t N> |
---|
| 50 | const T (*addressof(const T (&t)[N]))[N] |
---|
| 51 | { |
---|
| 52 | return reinterpret_cast<const T(*)[N]>(&t); |
---|
| 53 | } |
---|
| 54 | # endif |
---|
| 55 | |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | #endif // BOOST_UTILITY_ADDRESSOF_HPP |
---|