source: NonGTP/Boost/boost/utility/addressof.hpp @ 857

Revision 857, 1.5 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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
17namespace 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
24template<class T> struct _addp
25{
26    typedef T * type;
27};
28   
29template <typename T> typename _addp<T>::type
30
31# else
32template <typename T> T*
33# endif
34addressof(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))
43template<typename T,std::size_t N>
44T (*addressof(T (&t)[N]))[N]
45{
46   return reinterpret_cast<T(*)[N]>(&t);
47}
48
49template<typename T,std::size_t N>
50const 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
Note: See TracBrowser for help on using the repository browser.