imgtools/imglib/boostlibrary/boost/utility/addressof.hpp
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     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 addr_impl_ref
       
    25 {
       
    26     T & v_;
       
    27 
       
    28     inline addr_impl_ref( T & v ): v_( v ) {}
       
    29     inline operator T& () const { return v_; }
       
    30 };
       
    31 
       
    32 template<class T> struct addressof_impl
       
    33 {
       
    34     static inline T * f( T & v, long )
       
    35     {
       
    36         return reinterpret_cast<T*>(
       
    37             &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
       
    38     }
       
    39 
       
    40     static inline T * f( T * v, int )
       
    41     {
       
    42         return v;
       
    43     }
       
    44 };
       
    45 
       
    46 } // namespace detail
       
    47 
       
    48 template<class T> T * addressof( T & v )
       
    49 {
       
    50 #if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) )
       
    51 
       
    52     return boost::detail::addressof_impl<T>::f( v, 0 );
       
    53 
       
    54 #else
       
    55 
       
    56     return boost::detail::addressof_impl<T>::f( boost::detail::addr_impl_ref<T>( v ), 0 );
       
    57 
       
    58 #endif
       
    59 }
       
    60 
       
    61 #if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) )
       
    62 
       
    63 namespace detail
       
    64 {
       
    65 
       
    66 template<class T> struct addressof_addp
       
    67 {
       
    68     typedef T * type;
       
    69 };
       
    70 
       
    71 } // namespace detail
       
    72 
       
    73 template< class T, std::size_t N >
       
    74 typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] )
       
    75 {
       
    76     return &t;
       
    77 }
       
    78 
       
    79 #endif
       
    80 
       
    81 // Borland doesn't like casting an array reference to a char reference
       
    82 // but these overloads work around the problem.
       
    83 #if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
       
    84 template<typename T,std::size_t N>
       
    85 T (*addressof(T (&t)[N]))[N]
       
    86 {
       
    87    return reinterpret_cast<T(*)[N]>(&t);
       
    88 }
       
    89 
       
    90 template<typename T,std::size_t N>
       
    91 const T (*addressof(const T (&t)[N]))[N]
       
    92 {
       
    93    return reinterpret_cast<const T(*)[N]>(&t);
       
    94 }
       
    95 #endif
       
    96 
       
    97 } // namespace boost
       
    98 
       
    99 #endif // BOOST_UTILITY_ADDRESSOF_HPP