Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/boost/ref.hpp @ 13

Last change on this file since 13 was 12, checked in by landauf, 17 years ago

added boost

File size: 3.5 KB
Line 
1#ifndef BOOST_REF_HPP_INCLUDED
2#define BOOST_REF_HPP_INCLUDED
3
4// MS compatible compilers support #pragma once
5
6#if defined(_MSC_VER) && (_MSC_VER >= 1020)
7# pragma once
8#endif
9
10#include <boost/config.hpp>
11#include <boost/utility/addressof.hpp>
12#include <boost/mpl/bool.hpp>
13
14//
15//  ref.hpp - ref/cref, useful helper functions
16//
17//  Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
18//  Copyright (C) 2001, 2002 Peter Dimov
19//  Copyright (C) 2002 David Abrahams
20//
21// Distributed under the Boost Software License, Version 1.0. (See
22// accompanying file LICENSE_1_0.txt or copy at
23// http://www.boost.org/LICENSE_1_0.txt)
24//
25//  See http://www.boost.org/libs/bind/ref.html for documentation.
26//
27
28namespace boost
29{
30
31template<class T> class reference_wrapper
32{ 
33public:
34    typedef T type;
35
36#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
37
38    explicit reference_wrapper(T& t): t_(&t) {}
39
40#else
41
42    explicit reference_wrapper(T& t): t_(boost::addressof(t)) {}
43
44#endif
45
46    operator T& () const { return *t_; }
47
48    T& get() const { return *t_; }
49
50    T* get_pointer() const { return t_; }
51
52private:
53
54    T* t_;
55};
56
57# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
58#  define BOOST_REF_CONST
59# else
60#  define BOOST_REF_CONST const
61# endif
62
63template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
64{ 
65    return reference_wrapper<T>(t);
66}
67
68template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
69{
70    return reference_wrapper<T const>(t);
71}
72
73# undef BOOST_REF_CONST
74
75# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
76
77template<typename T>
78class is_reference_wrapper
79    : public mpl::false_
80{
81};
82
83template<typename T>
84class unwrap_reference
85{
86 public:
87    typedef T type;
88};
89
90#  define AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(X) \
91template<typename T> \
92class is_reference_wrapper< X > \
93    : public mpl::true_ \
94{ \
95}; \
96\
97template<typename T> \
98class unwrap_reference< X > \
99{ \
100 public: \
101    typedef T type; \
102}; \
103/**/
104
105AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T>)
106#if !defined(BOOST_NO_CV_SPECIALIZATIONS)
107AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const)
108AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> volatile)
109AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF(reference_wrapper<T> const volatile)
110#endif
111
112#  undef AUX_REFERENCE_WRAPPER_METAFUNCTIONS_DEF
113
114# else // no partial specialization
115
116} // namespace boost
117
118#include <boost/type.hpp>
119
120namespace boost
121{
122
123namespace detail
124{
125  typedef char (&yes_reference_wrapper_t)[1];
126  typedef char (&no_reference_wrapper_t)[2];
127     
128  no_reference_wrapper_t is_reference_wrapper_test(...);
129
130  template<typename T>
131  yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
132
133  template<bool wrapped>
134  struct reference_unwrapper
135  {
136      template <class T>
137      struct apply
138      {
139          typedef T type;
140      };
141  };
142
143  template<>
144  struct reference_unwrapper<true>
145  {
146      template <class T>
147      struct apply
148      {
149          typedef typename T::type type;
150      };
151  };
152}
153
154template<typename T>
155class is_reference_wrapper
156{
157 public:
158    BOOST_STATIC_CONSTANT(
159        bool, value = (
160             sizeof(detail::is_reference_wrapper_test(type<T>()))
161            == sizeof(detail::yes_reference_wrapper_t)));
162   
163    typedef ::boost::mpl::bool_<value> type;
164};
165
166template <typename T>
167class unwrap_reference
168    : public detail::reference_unwrapper<
169        is_reference_wrapper<T>::value
170      >::template apply<T>
171{};
172
173# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
174
175} // namespace boost
176
177#endif // #ifndef BOOST_REF_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.