os/ossrv/ossrv_pub/boost_apis/boost/utility/addressof.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (C) 2002 Brad King (brad.king@kitware.com) 
sl@0
     2
//                    Douglas Gregor (gregod@cs.rpi.edu)
sl@0
     3
//                    Peter Dimov
sl@0
     4
//
sl@0
     5
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     6
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     7
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     8
sl@0
     9
// For more information, see http://www.boost.org
sl@0
    10
sl@0
    11
#ifndef BOOST_UTILITY_ADDRESSOF_HPP
sl@0
    12
# define BOOST_UTILITY_ADDRESSOF_HPP
sl@0
    13
sl@0
    14
# include <boost/config.hpp>
sl@0
    15
# include <boost/detail/workaround.hpp>
sl@0
    16
sl@0
    17
namespace boost {
sl@0
    18
sl@0
    19
// Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov)
sl@0
    20
sl@0
    21
// VC7 strips const from nested classes unless we add indirection here
sl@0
    22
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
sl@0
    23
sl@0
    24
template<class T> struct _addp
sl@0
    25
{
sl@0
    26
    typedef T * type;
sl@0
    27
};
sl@0
    28
    
sl@0
    29
template <typename T> typename _addp<T>::type
sl@0
    30
sl@0
    31
# else
sl@0
    32
template <typename T> T*
sl@0
    33
# endif
sl@0
    34
addressof(T& v)
sl@0
    35
{
sl@0
    36
  return reinterpret_cast<T*>(
sl@0
    37
       &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
sl@0
    38
}
sl@0
    39
sl@0
    40
// Borland doesn't like casting an array reference to a char reference
sl@0
    41
// but these overloads work around the problem.
sl@0
    42
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
sl@0
    43
template<typename T,std::size_t N>
sl@0
    44
T (*addressof(T (&t)[N]))[N]
sl@0
    45
{
sl@0
    46
   return reinterpret_cast<T(*)[N]>(&t);
sl@0
    47
}
sl@0
    48
sl@0
    49
template<typename T,std::size_t N>
sl@0
    50
const T (*addressof(const T (&t)[N]))[N]
sl@0
    51
{
sl@0
    52
   return reinterpret_cast<const T(*)[N]>(&t);
sl@0
    53
}
sl@0
    54
# endif
sl@0
    55
sl@0
    56
}
sl@0
    57
sl@0
    58
#endif // BOOST_UTILITY_ADDRESSOF_HPP