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>
12 // ref.hpp - ref/cref, useful helper functions
14 // Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
15 // Copyright (C) 2001, 2002 Peter Dimov
16 // Copyright (C) 2002 David Abrahams
18 // Permission to copy, use, modify, sell and distribute this software
19 // is granted provided this copyright notice appears in all copies.
20 // This software is provided "as is" without express or implied
21 // warranty, and with no claim as to its suitability for any purpose.
23 // See http://www.boost.org/libs/bind/ref.html for documentation.
29 template<class T> class reference_wrapper
34 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
36 explicit reference_wrapper(T& t): t_(&t) {}
40 explicit reference_wrapper(T& t): t_(addressof(t)) {}
44 operator T& () const { return *t_; }
46 T& get() const { return *t_; }
48 T* get_pointer() const { return t_; }
55 # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
56 # define BOOST_REF_CONST
58 # define BOOST_REF_CONST const
61 template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
63 return reference_wrapper<T>(t);
66 template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
68 return reference_wrapper<T const>(t);
71 # undef BOOST_REF_CONST
73 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
75 class is_reference_wrapper
78 BOOST_STATIC_CONSTANT(bool, value = false);
82 class is_reference_wrapper<reference_wrapper<T> >
85 BOOST_STATIC_CONSTANT(bool, value = true);
89 class unwrap_reference
96 class unwrap_reference<reference_wrapper<T> >
101 # else // no partial specialization
105 #include <boost/type.hpp>
112 typedef char (&yes_reference_wrapper_t)[1];
113 typedef char (&no_reference_wrapper_t)[2];
115 no_reference_wrapper_t is_reference_wrapper_test(...);
118 yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
120 template<bool wrapped>
121 struct reference_unwrapper
131 struct reference_unwrapper<true>
136 typedef typename T::type type;
142 class is_reference_wrapper
145 BOOST_STATIC_CONSTANT(
147 sizeof(detail::is_reference_wrapper_test(type<T>()))
148 == sizeof(detail::yes_reference_wrapper_t)));
151 template <typename T>
152 class unwrap_reference
153 : public detail::reference_unwrapper<
154 is_reference_wrapper<T>::value
158 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
162 #endif // #ifndef BOOST_REF_HPP_INCLUDED