]> git.lyx.org Git - lyx.git/blobdiff - boost/boost/utility/addressof.hpp
boost: update to version 1.40
[lyx.git] / boost / boost / utility / addressof.hpp
index de8dfe5d5968c10aa8e2d0e90697a69bc26aba2e..95cd92fca9bb940ae0f9a289268a0fe4a9305b68 100644 (file)
@@ -1,15 +1,11 @@
 // Copyright (C) 2002 Brad King (brad.king@kitware.com) 
-//                    Doug Gregor (gregod@cs.rpi.edu)
-//                    Peter Dimov
+//                    Douglas Gregor (gregod@cs.rpi.edu)
 //
-// Permission to copy, use, sell and distribute this software is granted
-// provided this copyright notice appears in all copies.
-// Permission to modify the code and to distribute modified code is granted
-// provided this copyright notice appears in all copies, and a notice
-// that the code was modified is included with the copyright notice.
+// Copyright (C) 2002, 2008 Peter Dimov
 //
-// This software is provided "as is" without express or implied warranty,
-// and with no claim as to its suitability for any purpose.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
 
 // For more information, see http://www.boost.org
 
 
 # include <boost/config.hpp>
 # include <boost/detail/workaround.hpp>
-# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
-#  include <boost/type_traits/add_pointer.hpp>
-# endif
 
-namespace boost {
+namespace boost
+{
+
+namespace detail
+{
+
+template<class T> struct addr_impl_ref
+{
+    T & v_;
+
+    inline addr_impl_ref( T & v ): v_( v ) {}
+    inline operator T& () const { return v_; }
 
-// Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov)
+private:
+    addr_impl_ref & operator=(const addr_impl_ref &);
+};
 
-// VC7 strips const from nested classes unless we add indirection here
-# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
-template <typename T> typename add_pointer<T>::type
-# else
-template <typename T> T*
-# endif
-addressof(T& v)
+template<class T> struct addressof_impl
 {
-  return reinterpret_cast<T*>(
-       &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
+    static inline T * f( T & v, long )
+    {
+        return reinterpret_cast<T*>(
+            &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
+    }
+
+    static inline T * f( T * v, int )
+    {
+        return v;
+    }
+};
+
+} // namespace detail
+
+template<class T> T * addressof( T & v )
+{
+#if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) )
+
+    return boost::detail::addressof_impl<T>::f( v, 0 );
+
+#else
+
+    return boost::detail::addressof_impl<T>::f( boost::detail::addr_impl_ref<T>( v ), 0 );
+
+#endif
 }
 
+#if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) )
+
+namespace detail
+{
+
+template<class T> struct addressof_addp
+{
+    typedef T * type;
+};
+
+} // namespace detail
+
+template< class T, std::size_t N >
+typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] )
+{
+    return &t;
+}
+
+#endif
+
+// Borland doesn't like casting an array reference to a char reference
+// but these overloads work around the problem.
+#if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
+template<typename T,std::size_t N>
+T (*addressof(T (&t)[N]))[N]
+{
+   return reinterpret_cast<T(*)[N]>(&t);
 }
 
+template<typename T,std::size_t N>
+const T (*addressof(const T (&t)[N]))[N]
+{
+   return reinterpret_cast<const T(*)[N]>(&t);
+}
+#endif
+
+} // namespace boost
+
 #endif // BOOST_UTILITY_ADDRESSOF_HPP