]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/utility/addressof.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
717a45425024a4a23f80be7223c5800abb0a0569
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / utility / addressof.hpp
1 // Copyright (C) 2002 Brad King (brad.king@kitware.com) \r
2 //                    Douglas Gregor (gregod@cs.rpi.edu)\r
3 //\r
4 // Copyright (C) 2002, 2008 Peter Dimov\r
5 //\r
6 // Distributed under the Boost Software License, Version 1.0. (See\r
7 // accompanying file LICENSE_1_0.txt or copy at\r
8 // http://www.boost.org/LICENSE_1_0.txt)\r
9 \r
10 // For more information, see http://www.boost.org\r
11 \r
12 #ifndef BOOST_UTILITY_ADDRESSOF_HPP\r
13 # define BOOST_UTILITY_ADDRESSOF_HPP\r
14 \r
15 # include <boost/config.hpp>\r
16 # include <boost/detail/workaround.hpp>\r
17 \r
18 namespace boost\r
19 {\r
20 \r
21 namespace detail\r
22 {\r
23 \r
24 template<class T> struct addr_impl_ref\r
25 {\r
26     T & v_;\r
27 \r
28     inline addr_impl_ref( T & v ): v_( v ) {}\r
29     inline operator T& () const { return v_; }\r
30 \r
31 private:\r
32     addr_impl_ref & operator=(const addr_impl_ref &);\r
33 };\r
34 \r
35 template<class T> struct addressof_impl\r
36 {\r
37     static inline T * f( T & v, long )\r
38     {\r
39         return reinterpret_cast<T*>(\r
40             &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));\r
41     }\r
42 \r
43     static inline T * f( T * v, int )\r
44     {\r
45         return v;\r
46     }\r
47 };\r
48 \r
49 } // namespace detail\r
50 \r
51 template<class T> T * addressof( T & v )\r
52 {\r
53 #if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) )\r
54 \r
55     return boost::detail::addressof_impl<T>::f( v, 0 );\r
56 \r
57 #else\r
58 \r
59     return boost::detail::addressof_impl<T>::f( boost::detail::addr_impl_ref<T>( v ), 0 );\r
60 \r
61 #endif\r
62 }\r
63 \r
64 #if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) )\r
65 \r
66 namespace detail\r
67 {\r
68 \r
69 template<class T> struct addressof_addp\r
70 {\r
71     typedef T * type;\r
72 };\r
73 \r
74 } // namespace detail\r
75 \r
76 template< class T, std::size_t N >\r
77 typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] )\r
78 {\r
79     return &t;\r
80 }\r
81 \r
82 #endif\r
83 \r
84 // Borland doesn't like casting an array reference to a char reference\r
85 // but these overloads work around the problem.\r
86 #if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))\r
87 template<typename T,std::size_t N>\r
88 T (*addressof(T (&t)[N]))[N]\r
89 {\r
90    return reinterpret_cast<T(*)[N]>(&t);\r
91 }\r
92 \r
93 template<typename T,std::size_t N>\r
94 const T (*addressof(const T (&t)[N]))[N]\r
95 {\r
96    return reinterpret_cast<const T(*)[N]>(&t);\r
97 }\r
98 #endif\r
99 \r
100 } // namespace boost\r
101 \r
102 #endif // BOOST_UTILITY_ADDRESSOF_HPP\r