]> git.lyx.org Git - lyx.git/blob - boost/boost/utility/addressof.hpp
update boost to version 1.36
[lyx.git] / boost / boost / utility / addressof.hpp
1 // Copyright (C) 2002 Brad King (brad.king@kitware.com) 
2 //                    Douglas Gregor (gregod@cs.rpi.edu)
3 //
4 // Copyright (C) 2002, 2008 Peter Dimov
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 // For more information, see http://www.boost.org
11
12 #ifndef BOOST_UTILITY_ADDRESSOF_HPP
13 # define BOOST_UTILITY_ADDRESSOF_HPP
14
15 # include <boost/config.hpp>
16 # include <boost/detail/workaround.hpp>
17
18 namespace boost
19 {
20
21 namespace detail
22 {
23
24 template<class T> struct addressof_impl
25 {
26     static inline T * f( T & v, long )
27     {
28         return reinterpret_cast<T*>(
29             &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
30     }
31
32     static inline T * f( T * v, int )
33     {
34         return v;
35     }
36 };
37
38 } // namespace detail
39
40 template<class T> T * addressof( T & v )
41 {
42     return boost::detail::addressof_impl<T>::f( v, 0 );
43 }
44
45 // Borland doesn't like casting an array reference to a char reference
46 // but these overloads work around the problem.
47 # if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
48 template<typename T,std::size_t N>
49 T (*addressof(T (&t)[N]))[N]
50 {
51    return reinterpret_cast<T(*)[N]>(&t);
52 }
53
54 template<typename T,std::size_t N>
55 const T (*addressof(const T (&t)[N]))[N]
56 {
57    return reinterpret_cast<const T(*)[N]>(&t);
58 }
59 # endif
60
61 } // namespace boost
62
63 #endif // BOOST_UTILITY_ADDRESSOF_HPP