src/sysc/packages/boost/ref.hpp

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

Generated on Wed Apr 25 13:53:28 2007 for SystemC by  doxygen 1.5.1