ref.hpp

Go to the documentation of this file.
00001 #ifndef BOOST_REF_HPP_INCLUDED
00002 #define BOOST_REF_HPP_INCLUDED
00003 
00004 // MS compatible compilers support #pragma once
00005 
00006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
00007 # pragma once
00008 #endif
00009 
00010 #include <sysc/packages/boost/config.hpp>
00011 #include <sysc/packages/boost/utility/addressof.hpp>
00012 #include <sysc/packages/boost/mpl/bool.hpp>
00013 
00014 //
00015 //  ref.hpp - ref/cref, useful helper functions
00016 //
00017 //  Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
00018 //  Copyright (C) 2001, 2002 Peter Dimov
00019 //  Copyright (C) 2002 David Abrahams
00020 //
00021 // Distributed under the Boost Software License, Version 1.0. (See
00022 // accompanying file LICENSE_1_0.txt or copy at
00023 // http://www.boost.org/LICENSE_1_0.txt)
00024 //
00025 //  See http://www.boost.org/libs/bind/ref.html for documentation.
00026 //
00027 
00028 namespace boost
00029 {
00030 
00031 template<class T> class reference_wrapper
00032 { 
00033 public:
00034     typedef T type;
00035 
00036 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
00037 
00038     explicit reference_wrapper(T& t): t_(&t) {}
00039 
00040 #else
00041 
00042     explicit reference_wrapper(T& t): t_(boost::addressof(t)) {}
00043 
00044 #endif
00045 
00046     operator T& () const { return *t_; }
00047 
00048     T& get() const { return *t_; }
00049 
00050     T* get_pointer() const { return t_; }
00051 
00052 private:
00053 
00054     T* t_;
00055 };
00056 
00057 # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
00058 #  define BOOST_REF_CONST
00059 # else
00060 #  define BOOST_REF_CONST const
00061 # endif
00062 
00063 template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
00064 { 
00065     return reference_wrapper<T>(t);
00066 }
00067 
00068 template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
00069 {
00070     return reference_wrapper<T const>(t);
00071 }
00072 
00073 # undef BOOST_REF_CONST
00074 
00075 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00076 
00077 template<typename T>
00078 class is_reference_wrapper
00079     : public mpl::false_
00080 {
00081 };
00082 
00083 template<typename T>
00084 class unwrap_reference
00085 {
00086  public:
00087     typedef T type;
00088 };
00089 
00090 #  define AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(X) \
00091 template<typename T> \
00092 class is_reference_wrapper< X > \
00093     : public mpl::true_ \
00094 { \
00095 }; \
00096 \
00097 template<typename T> \
00098 class unwrap_reference< X > \
00099 { \
00100  public: \
00101     typedef T type; \
00102 }; \
00103 /**/
00104 
00105 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T>)
00106 #if !defined(BOOST_NO_CV_SPECIALIZATIONS)
00107 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const)
00108 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> volatile)
00109 AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const volatile)
00110 #endif
00111 
00112 #  undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF
00113 
00114 # else // no partial specialization
00115 
00116 } // namespace boost
00117 
00118 #include <sysc/packages/boost/type.hpp>
00119 
00120 namespace boost
00121 {
00122 
00123 namespace detail
00124 {
00125   typedef char (&yes_reference_wrapper_t)[1];
00126   typedef char (&no_reference_wrapper_t)[2];
00127       
00128   no_reference_wrapper_t is_reference_wrapper_test(...);
00129 
00130   template<typename T>
00131   yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
00132 
00133   template<bool wrapped>
00134   struct reference_unwrapper
00135   {
00136       template <class T>
00137       struct apply
00138       {
00139           typedef T type;
00140       };
00141   };
00142 
00143   template<>
00144   struct reference_unwrapper<true>
00145   {
00146       template <class T>
00147       struct apply
00148       {
00149           typedef typename T::type type;
00150       };
00151   };
00152 }
00153 
00154 template<typename T>
00155 class is_reference_wrapper
00156 {
00157  public:
00158     BOOST_STATIC_CONSTANT(
00159         bool, value = (
00160              sizeof(detail::is_reference_wrapper_test(type<T>()))
00161             == sizeof(detail::yes_reference_wrapper_t)));
00162     
00163     typedef ::boost::mpl::bool_<value> type;
00164 };
00165 
00166 template <typename T>
00167 class unwrap_reference
00168     : public detail::reference_unwrapper<
00169         is_reference_wrapper<T>::value
00170       >::template apply<T>
00171 {};
00172 
00173 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
00174 
00175 } // namespace boost
00176 
00177 #endif // #ifndef BOOST_REF_HPP_INCLUDED

Generated on Wed Jan 21 15:32:10 2009 for SystemC by  doxygen 1.5.5