author | William Roberts <williamr@symbian.org> |
Wed, 31 Mar 2010 12:27:01 +0100 | |
branch | Symbian2 |
changeset 3 | e1b950c65cb4 |
permissions | -rw-r--r-- |
williamr@2 | 1 |
#ifndef BOOST_REF_HPP_INCLUDED |
williamr@2 | 2 |
#define BOOST_REF_HPP_INCLUDED |
williamr@2 | 3 |
|
williamr@2 | 4 |
// MS compatible compilers support #pragma once |
williamr@2 | 5 |
|
williamr@2 | 6 |
#if defined(_MSC_VER) && (_MSC_VER >= 1020) |
williamr@2 | 7 |
# pragma once |
williamr@2 | 8 |
#endif |
williamr@2 | 9 |
|
williamr@2 | 10 |
#include <boost/config.hpp> |
williamr@2 | 11 |
#include <boost/utility/addressof.hpp> |
williamr@2 | 12 |
#include <boost/mpl/bool.hpp> |
williamr@2 | 13 |
#include <boost/detail/workaround.hpp> |
williamr@2 | 14 |
|
williamr@2 | 15 |
// |
williamr@2 | 16 |
// ref.hpp - ref/cref, useful helper functions |
williamr@2 | 17 |
// |
williamr@2 | 18 |
// Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) |
williamr@2 | 19 |
// Copyright (C) 2001, 2002 Peter Dimov |
williamr@2 | 20 |
// Copyright (C) 2002 David Abrahams |
williamr@2 | 21 |
// |
williamr@2 | 22 |
// Distributed under the Boost Software License, Version 1.0. (See |
williamr@2 | 23 |
// accompanying file LICENSE_1_0.txt or copy at |
williamr@2 | 24 |
// http://www.boost.org/LICENSE_1_0.txt) |
williamr@2 | 25 |
// |
williamr@2 | 26 |
// See http://www.boost.org/libs/bind/ref.html for documentation. |
williamr@2 | 27 |
// |
williamr@2 | 28 |
|
williamr@2 | 29 |
namespace boost |
williamr@2 | 30 |
{ |
williamr@2 | 31 |
|
williamr@2 | 32 |
template<class T> class reference_wrapper |
williamr@2 | 33 |
{ |
williamr@2 | 34 |
public: |
williamr@2 | 35 |
typedef T type; |
williamr@2 | 36 |
|
williamr@2 | 37 |
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 ) |
williamr@2 | 38 |
|
williamr@2 | 39 |
explicit reference_wrapper(T& t): t_(&t) {} |
williamr@2 | 40 |
|
williamr@2 | 41 |
#else |
williamr@2 | 42 |
|
williamr@2 | 43 |
explicit reference_wrapper(T& t): t_(boost::addressof(t)) {} |
williamr@2 | 44 |
|
williamr@2 | 45 |
#endif |
williamr@2 | 46 |
|
williamr@2 | 47 |
operator T& () const { return *t_; } |
williamr@2 | 48 |
|
williamr@2 | 49 |
T& get() const { return *t_; } |
williamr@2 | 50 |
|
williamr@2 | 51 |
T* get_pointer() const { return t_; } |
williamr@2 | 52 |
|
williamr@2 | 53 |
private: |
williamr@2 | 54 |
|
williamr@2 | 55 |
T* t_; |
williamr@2 | 56 |
}; |
williamr@2 | 57 |
|
williamr@2 | 58 |
# if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x581) ) |
williamr@2 | 59 |
# define BOOST_REF_CONST |
williamr@2 | 60 |
# else |
williamr@2 | 61 |
# define BOOST_REF_CONST const |
williamr@2 | 62 |
# endif |
williamr@2 | 63 |
|
williamr@2 | 64 |
template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t) |
williamr@2 | 65 |
{ |
williamr@2 | 66 |
return reference_wrapper<T>(t); |
williamr@2 | 67 |
} |
williamr@2 | 68 |
|
williamr@2 | 69 |
template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t) |
williamr@2 | 70 |
{ |
williamr@2 | 71 |
return reference_wrapper<T const>(t); |
williamr@2 | 72 |
} |
williamr@2 | 73 |
|
williamr@2 | 74 |
# undef BOOST_REF_CONST |
williamr@2 | 75 |
|
williamr@2 | 76 |
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
williamr@2 | 77 |
|
williamr@2 | 78 |
template<typename T> |
williamr@2 | 79 |
class is_reference_wrapper |
williamr@2 | 80 |
: public mpl::false_ |
williamr@2 | 81 |
{ |
williamr@2 | 82 |
}; |
williamr@2 | 83 |
|
williamr@2 | 84 |
template<typename T> |
williamr@2 | 85 |
class unwrap_reference |
williamr@2 | 86 |
{ |
williamr@2 | 87 |
public: |
williamr@2 | 88 |
typedef T type; |
williamr@2 | 89 |
}; |
williamr@2 | 90 |
|
williamr@2 | 91 |
# define AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(X) \ |
williamr@2 | 92 |
template<typename T> \ |
williamr@2 | 93 |
class is_reference_wrapper< X > \ |
williamr@2 | 94 |
: public mpl::true_ \ |
williamr@2 | 95 |
{ \ |
williamr@2 | 96 |
}; \ |
williamr@2 | 97 |
\ |
williamr@2 | 98 |
template<typename T> \ |
williamr@2 | 99 |
class unwrap_reference< X > \ |
williamr@2 | 100 |
{ \ |
williamr@2 | 101 |
public: \ |
williamr@2 | 102 |
typedef T type; \ |
williamr@2 | 103 |
}; \ |
williamr@2 | 104 |
/**/ |
williamr@2 | 105 |
|
williamr@2 | 106 |
AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T>) |
williamr@2 | 107 |
#if !defined(BOOST_NO_CV_SPECIALIZATIONS) |
williamr@2 | 108 |
AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const) |
williamr@2 | 109 |
AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> volatile) |
williamr@2 | 110 |
AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const volatile) |
williamr@2 | 111 |
#endif |
williamr@2 | 112 |
|
williamr@2 | 113 |
# undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF |
williamr@2 | 114 |
|
williamr@2 | 115 |
# else // no partial specialization |
williamr@2 | 116 |
|
williamr@2 | 117 |
} // namespace boost |
williamr@2 | 118 |
|
williamr@2 | 119 |
#include <boost/type.hpp> |
williamr@2 | 120 |
|
williamr@2 | 121 |
namespace boost |
williamr@2 | 122 |
{ |
williamr@2 | 123 |
|
williamr@2 | 124 |
namespace detail |
williamr@2 | 125 |
{ |
williamr@2 | 126 |
typedef char (&yes_reference_wrapper_t)[1]; |
williamr@2 | 127 |
typedef char (&no_reference_wrapper_t)[2]; |
williamr@2 | 128 |
|
williamr@2 | 129 |
no_reference_wrapper_t is_reference_wrapper_test(...); |
williamr@2 | 130 |
|
williamr@2 | 131 |
template<typename T> |
williamr@2 | 132 |
yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >); |
williamr@2 | 133 |
|
williamr@2 | 134 |
template<bool wrapped> |
williamr@2 | 135 |
struct reference_unwrapper |
williamr@2 | 136 |
{ |
williamr@2 | 137 |
template <class T> |
williamr@2 | 138 |
struct apply |
williamr@2 | 139 |
{ |
williamr@2 | 140 |
typedef T type; |
williamr@2 | 141 |
}; |
williamr@2 | 142 |
}; |
williamr@2 | 143 |
|
williamr@2 | 144 |
template<> |
williamr@2 | 145 |
struct reference_unwrapper<true> |
williamr@2 | 146 |
{ |
williamr@2 | 147 |
template <class T> |
williamr@2 | 148 |
struct apply |
williamr@2 | 149 |
{ |
williamr@2 | 150 |
typedef typename T::type type; |
williamr@2 | 151 |
}; |
williamr@2 | 152 |
}; |
williamr@2 | 153 |
} |
williamr@2 | 154 |
|
williamr@2 | 155 |
template<typename T> |
williamr@2 | 156 |
class is_reference_wrapper |
williamr@2 | 157 |
{ |
williamr@2 | 158 |
public: |
williamr@2 | 159 |
BOOST_STATIC_CONSTANT( |
williamr@2 | 160 |
bool, value = ( |
williamr@2 | 161 |
sizeof(detail::is_reference_wrapper_test(type<T>())) |
williamr@2 | 162 |
== sizeof(detail::yes_reference_wrapper_t))); |
williamr@2 | 163 |
|
williamr@2 | 164 |
typedef ::boost::mpl::bool_<value> type; |
williamr@2 | 165 |
}; |
williamr@2 | 166 |
|
williamr@2 | 167 |
template <typename T> |
williamr@2 | 168 |
class unwrap_reference |
williamr@2 | 169 |
: public detail::reference_unwrapper< |
williamr@2 | 170 |
is_reference_wrapper<T>::value |
williamr@2 | 171 |
>::template apply<T> |
williamr@2 | 172 |
{}; |
williamr@2 | 173 |
|
williamr@2 | 174 |
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
williamr@2 | 175 |
|
williamr@2 | 176 |
} // namespace boost |
williamr@2 | 177 |
|
williamr@2 | 178 |
#endif // #ifndef BOOST_REF_HPP_INCLUDED |