1 #ifndef BOOST_REF_HPP_INCLUDED
\r
2 #define BOOST_REF_HPP_INCLUDED
\r
4 // MS compatible compilers support #pragma once
\r
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
\r
10 #include <boost/config.hpp>
\r
11 #include <boost/utility/addressof.hpp>
\r
12 #include <boost/mpl/bool.hpp>
\r
13 #include <boost/detail/workaround.hpp>
\r
16 // ref.hpp - ref/cref, useful helper functions
\r
18 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
\r
19 // Copyright (C) 2001, 2002 Peter Dimov
\r
20 // Copyright (C) 2002 David Abrahams
\r
22 // Distributed under the Boost Software License, Version 1.0. (See
\r
23 // accompanying file LICENSE_1_0.txt or copy at
\r
24 // http://www.boost.org/LICENSE_1_0.txt)
\r
26 // See http://www.boost.org/libs/bind/ref.html for documentation.
\r
32 template<class T> class reference_wrapper
\r
37 #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 )
\r
39 explicit reference_wrapper(T& t): t_(&t) {}
\r
43 explicit reference_wrapper(T& t): t_(boost::addressof(t)) {}
\r
47 operator T& () const { return *t_; }
\r
49 T& get() const { return *t_; }
\r
51 T* get_pointer() const { return t_; }
\r
58 # if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x581) )
\r
59 # define BOOST_REF_CONST
\r
61 # define BOOST_REF_CONST const
\r
64 template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
\r
66 return reference_wrapper<T>(t);
\r
69 template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
\r
71 return reference_wrapper<T const>(t);
\r
74 # undef BOOST_REF_CONST
\r
76 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
\r
78 template<typename T>
\r
79 class is_reference_wrapper
\r
80 : public mpl::false_
\r
84 template<typename T>
\r
85 class unwrap_reference
\r
91 # define AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(X) \
\r
92 template<typename T> \
\r
93 class is_reference_wrapper< X > \
\r
94 : public mpl::true_ \
\r
98 template<typename T> \
\r
99 class unwrap_reference< X > \
\r
106 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T>)
\r
107 #if !defined(BOOST_NO_CV_SPECIALIZATIONS)
\r
108 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const)
\r
109 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> volatile)
\r
110 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const volatile)
\r
113 # undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF
\r
115 # else // no partial specialization
\r
117 } // namespace boost
\r
119 #include <boost/type.hpp>
\r
126 typedef char (&yes_reference_wrapper_t)[1];
\r
127 typedef char (&no_reference_wrapper_t)[2];
\r
129 no_reference_wrapper_t is_reference_wrapper_test(...);
\r
131 template<typename T>
\r
132 yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
\r
134 template<bool wrapped>
\r
135 struct reference_unwrapper
\r
145 struct reference_unwrapper<true>
\r
150 typedef typename T::type type;
\r
155 template<typename T>
\r
156 class is_reference_wrapper
\r
159 BOOST_STATIC_CONSTANT(
\r
161 sizeof(detail::is_reference_wrapper_test(type<T>()))
\r
162 == sizeof(detail::yes_reference_wrapper_t)));
\r
164 typedef ::boost::mpl::bool_<value> type;
\r
167 template <typename T>
\r
168 class unwrap_reference
\r
169 : public detail::reference_unwrapper<
\r
170 is_reference_wrapper<T>::value
\r
171 >::template apply<T>
\r
174 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
\r
176 template <class T> inline typename unwrap_reference<T>::type&
\r
182 template<class T> inline T* get_pointer( reference_wrapper<T> const & r )
\r
184 return r.get_pointer();
\r
187 } // namespace boost
\r
189 #endif // #ifndef BOOST_REF_HPP_INCLUDED
\r