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