]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/ref.hpp
Logo AND Algorithmique Numérique Distribuée

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