1 #ifndef BOOST_REF_HPP_INCLUDED
2 # define BOOST_REF_HPP_INCLUDED
4 # if _MSC_VER+0 >= 1020
8 # include <boost/config.hpp>
9 # include <boost/utility/addressof.hpp>
10 # include <boost/mpl/bool.hpp>
13 // ref.hpp - ref/cref, useful helper functions
15 // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
16 // Copyright (C) 2001, 2002 Peter Dimov
17 // Copyright (C) 2002 David Abrahams
19 // Permission to copy, use, modify, sell and distribute this software
20 // is granted provided this copyright notice appears in all copies.
21 // This software is provided "as is" without express or implied
22 // warranty, and with no claim as to its suitability for any purpose.
24 // See http://www.boost.org/libs/bind/ref.html for documentation.
30 template<class T> class reference_wrapper
35 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
37 explicit reference_wrapper(T& t): t_(&t) {}
41 explicit reference_wrapper(T& t): t_(addressof(t)) {}
45 operator T& () const { return *t_; }
47 T& get() const { return *t_; }
49 T* get_pointer() const { return t_; }
56 # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
57 # define BOOST_REF_CONST
59 # define BOOST_REF_CONST const
62 template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
64 return reference_wrapper<T>(t);
67 template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
69 return reference_wrapper<T const>(t);
72 # undef BOOST_REF_CONST
74 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
76 class is_reference_wrapper
82 class is_reference_wrapper<reference_wrapper<T> >
88 class unwrap_reference
95 class unwrap_reference<reference_wrapper<T> >
100 # else // no partial specialization
104 #include <boost/type.hpp>
111 typedef char (&yes_reference_wrapper_t)[1];
112 typedef char (&no_reference_wrapper_t)[2];
114 no_reference_wrapper_t is_reference_wrapper_test(...);
117 yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
119 template<bool wrapped>
120 struct reference_unwrapper
130 struct reference_unwrapper<true>
135 typedef typename T::type type;
141 class is_reference_wrapper
144 BOOST_STATIC_CONSTANT(
146 sizeof(detail::is_reference_wrapper_test(type<T>()))
147 == sizeof(detail::yes_reference_wrapper_t)));
149 typedef ::boost::mpl::bool_<value> type;
152 template <typename T>
153 class unwrap_reference
154 : public detail::reference_unwrapper<
155 is_reference_wrapper<T>::value
159 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
163 #endif // #ifndef BOOST_REF_HPP_INCLUDED