diff --git a/include/boost/ref.hpp b/include/boost/ref.hpp index 8ba1cfe..b6b4704 100644 --- a/include/boost/ref.hpp +++ b/include/boost/ref.hpp @@ -1,9 +1,9 @@ #ifndef BOOST_REF_HPP_INCLUDED -#define BOOST_REF_HPP_INCLUDED +# define BOOST_REF_HPP_INCLUDED -#if _MSC_VER+0 >= 1020 -#pragma once -#endif +# if _MSC_VER+0 >= 1020 +# pragma once +# endif // // ref.hpp - ref/cref, useful helper functions @@ -25,6 +25,7 @@ namespace boost template class reference_wrapper { public: + typedef T type; explicit reference_wrapper(T & t): t_(t) {} @@ -39,11 +40,11 @@ private: reference_wrapper & operator= (reference_wrapper const &); }; -#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) -#define BOOST_REF_CONST -#else -#define BOOST_REF_CONST const -#endif +# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) +# define BOOST_REF_CONST +# else +# define BOOST_REF_CONST const +# endif template inline reference_wrapper BOOST_REF_CONST ref(T & t) { @@ -55,7 +56,87 @@ template inline reference_wrapper BOOST_REF_CONST cref(T const return reference_wrapper(t); } -#undef BOOST_REF_CONST +# undef BOOST_REF_CONST + +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +template +class is_reference_wrapper +{ + public: + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +class is_reference_wrapper > +{ + public: + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +class unwrap_reference +{ + public: + typedef T type; +}; + +template +class unwrap_reference > +{ + public: + typedef T type; +}; +# else // no partial specialization +namespace detail +{ + typedef char (&yes_reference_wrapper_t)[1]; + typedef char (&no_reference_wrapper_t)[2]; + + no_reference_wrapper_t is_reference_wrapper_test(...); + + template + yes_reference_wrapper_t is_reference_wrapper_test(reference_wrapper*); + + template + struct reference_unwrapper + { + template + struct apply + { + typedef T type; + }; + }; + + template<> + struct reference_unwrapper + { + template + struct apply + { + typedef typename T::type type; + }; + }; +} + +template +class is_reference_wrapper +{ + public: + static T* t; + BOOST_STATIC_CONSTANT( + bool, value = ( + sizeof(detail::is_reference_wrapper_test(t)) + == sizeof(detail::yes_reference_wrapper_t))); +}; + +template +class unwrap_reference + : public detail::reference_unwrapper< + is_reference_wrapper::value + >::template apply +{}; + +# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION } // namespace boost