1 #ifndef BOOST_REF_HPP_INCLUDED
2 #define BOOST_REF_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
10 #include <boost/config.hpp>
11 #include <boost/utility/addressof.hpp>
12 #include <boost/mpl/bool.hpp>
15 // ref.hpp - ref/cref, useful helper functions
17 // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
18 // Copyright (C) 2001, 2002 Peter Dimov
19 // Copyright (C) 2002 David Abrahams
21 // Distributed under the Boost Software License, Version 1.0. (See
22 // accompanying file LICENSE_1_0.txt or copy at
23 // http://www.boost.org/LICENSE_1_0.txt)
25 // See http://www.boost.org/libs/bind/ref.html for documentation.
31 template<class T> class reference_wrapper
36 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
38 explicit reference_wrapper(T& t): t_(&t) {}
42 explicit reference_wrapper(T& t): t_(boost::addressof(t)) {}
46 operator T& () const { return *t_; }
48 T& get() const { return *t_; }
50 T* get_pointer() const { return t_; }
57 # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
58 # define BOOST_REF_CONST
60 # define BOOST_REF_CONST const
63 template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
65 return reference_wrapper<T>(t);
68 template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
70 return reference_wrapper<T const>(t);
73 # undef BOOST_REF_CONST
75 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
78 class is_reference_wrapper
84 class unwrap_reference
90 # define AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(X) \
91 template<typename T> \
92 class is_reference_wrapper< X > \
97 template<typename T> \
98 class unwrap_reference< X > \
105 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T>)
106 #if !defined(BOOST_NO_CV_SPECIALIZATIONS)
107 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const)
108 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> volatile)
109 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const volatile)
112 # undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF
114 # else // no partial specialization
118 #include <boost/type.hpp>
125 typedef char (&yes_reference_wrapper_t)[1];
126 typedef char (&no_reference_wrapper_t)[2];
128 no_reference_wrapper_t is_reference_wrapper_test(...);
131 yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
133 template<bool wrapped>
134 struct reference_unwrapper
144 struct reference_unwrapper<true>
149 typedef typename T::type type;
155 class is_reference_wrapper
158 BOOST_STATIC_CONSTANT(
160 sizeof(detail::is_reference_wrapper_test(type<T>()))
161 == sizeof(detail::yes_reference_wrapper_t)));
163 typedef ::boost::mpl::bool_<value> type;
166 template <typename T>
167 class unwrap_reference
168 : public detail::reference_unwrapper<
169 is_reference_wrapper<T>::value
173 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
177 #endif // #ifndef BOOST_REF_HPP_INCLUDED