|
1 #ifndef BOOST_MEM_FN_HPP_INCLUDED |
|
2 #define BOOST_MEM_FN_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 // |
|
11 // mem_fn.hpp - a generalization of std::mem_fun[_ref] |
|
12 // |
|
13 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. |
|
14 // Copyright (c) 2001 David Abrahams |
|
15 // Copyright (c) 2003-2005 Peter Dimov |
|
16 // |
|
17 // Distributed under the Boost Software License, Version 1.0. (See |
|
18 // accompanying file LICENSE_1_0.txt or copy at |
|
19 // http://www.boost.org/LICENSE_1_0.txt) |
|
20 // |
|
21 // See http://www.boost.org/libs/bind/mem_fn.html for documentation. |
|
22 // |
|
23 |
|
24 #include <boost/config.hpp> |
|
25 #include <boost/get_pointer.hpp> |
|
26 #include <boost/detail/workaround.hpp> |
|
27 |
|
28 namespace boost |
|
29 { |
|
30 |
|
31 #if defined(BOOST_NO_VOID_RETURNS) |
|
32 |
|
33 #define BOOST_MEM_FN_CLASS_F , class F |
|
34 #define BOOST_MEM_FN_TYPEDEF(X) |
|
35 |
|
36 namespace _mfi // mem_fun_impl |
|
37 { |
|
38 |
|
39 template<class V> struct mf |
|
40 { |
|
41 |
|
42 #define BOOST_MEM_FN_RETURN return |
|
43 |
|
44 #define BOOST_MEM_FN_NAME(X) inner_##X |
|
45 #define BOOST_MEM_FN_CC |
|
46 |
|
47 #include <boost/bind/mem_fn_template.hpp> |
|
48 |
|
49 #undef BOOST_MEM_FN_CC |
|
50 #undef BOOST_MEM_FN_NAME |
|
51 |
|
52 #ifdef BOOST_MEM_FN_ENABLE_CDECL |
|
53 |
|
54 #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl |
|
55 #define BOOST_MEM_FN_CC __cdecl |
|
56 |
|
57 #include <boost/bind/mem_fn_template.hpp> |
|
58 |
|
59 #undef BOOST_MEM_FN_CC |
|
60 #undef BOOST_MEM_FN_NAME |
|
61 |
|
62 #endif |
|
63 |
|
64 #ifdef BOOST_MEM_FN_ENABLE_STDCALL |
|
65 |
|
66 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall |
|
67 #define BOOST_MEM_FN_CC __stdcall |
|
68 |
|
69 #include <boost/bind/mem_fn_template.hpp> |
|
70 |
|
71 #undef BOOST_MEM_FN_CC |
|
72 #undef BOOST_MEM_FN_NAME |
|
73 |
|
74 #endif |
|
75 |
|
76 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL |
|
77 |
|
78 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall |
|
79 #define BOOST_MEM_FN_CC __fastcall |
|
80 |
|
81 #include <boost/bind/mem_fn_template.hpp> |
|
82 |
|
83 #undef BOOST_MEM_FN_CC |
|
84 #undef BOOST_MEM_FN_NAME |
|
85 |
|
86 #endif |
|
87 |
|
88 #undef BOOST_MEM_FN_RETURN |
|
89 |
|
90 }; // struct mf<V> |
|
91 |
|
92 template<> struct mf<void> |
|
93 { |
|
94 |
|
95 #define BOOST_MEM_FN_RETURN |
|
96 |
|
97 #define BOOST_MEM_FN_NAME(X) inner_##X |
|
98 #define BOOST_MEM_FN_CC |
|
99 |
|
100 #include <boost/bind/mem_fn_template.hpp> |
|
101 |
|
102 #undef BOOST_MEM_FN_CC |
|
103 #undef BOOST_MEM_FN_NAME |
|
104 |
|
105 #ifdef BOOST_MEM_FN_ENABLE_CDECL |
|
106 |
|
107 #define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl |
|
108 #define BOOST_MEM_FN_CC __cdecl |
|
109 |
|
110 #include <boost/bind/mem_fn_template.hpp> |
|
111 |
|
112 #undef BOOST_MEM_FN_CC |
|
113 #undef BOOST_MEM_FN_NAME |
|
114 |
|
115 #endif |
|
116 |
|
117 #ifdef BOOST_MEM_FN_ENABLE_STDCALL |
|
118 |
|
119 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall |
|
120 #define BOOST_MEM_FN_CC __stdcall |
|
121 |
|
122 #include <boost/bind/mem_fn_template.hpp> |
|
123 |
|
124 #undef BOOST_MEM_FN_CC |
|
125 #undef BOOST_MEM_FN_NAME |
|
126 |
|
127 #endif |
|
128 |
|
129 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL |
|
130 |
|
131 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall |
|
132 #define BOOST_MEM_FN_CC __fastcall |
|
133 |
|
134 #include <boost/bind/mem_fn_template.hpp> |
|
135 |
|
136 #undef BOOST_MEM_FN_CC |
|
137 #undef BOOST_MEM_FN_NAME |
|
138 |
|
139 #endif |
|
140 |
|
141 #undef BOOST_MEM_FN_RETURN |
|
142 |
|
143 }; // struct mf<void> |
|
144 |
|
145 #undef BOOST_MEM_FN_CLASS_F |
|
146 #undef BOOST_MEM_FN_TYPEDEF_F |
|
147 |
|
148 #define BOOST_MEM_FN_NAME(X) X |
|
149 #define BOOST_MEM_FN_NAME2(X) inner_##X |
|
150 #define BOOST_MEM_FN_CC |
|
151 |
|
152 #include <boost/bind/mem_fn_vw.hpp> |
|
153 |
|
154 #undef BOOST_MEM_FN_NAME |
|
155 #undef BOOST_MEM_FN_NAME2 |
|
156 #undef BOOST_MEM_FN_CC |
|
157 |
|
158 #ifdef BOOST_MEM_FN_ENABLE_CDECL |
|
159 |
|
160 #define BOOST_MEM_FN_NAME(X) X##_cdecl |
|
161 #define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl |
|
162 #define BOOST_MEM_FN_CC __cdecl |
|
163 |
|
164 #include <boost/bind/mem_fn_vw.hpp> |
|
165 |
|
166 #undef BOOST_MEM_FN_NAME |
|
167 #undef BOOST_MEM_FN_NAME2 |
|
168 #undef BOOST_MEM_FN_CC |
|
169 |
|
170 #endif |
|
171 |
|
172 #ifdef BOOST_MEM_FN_ENABLE_STDCALL |
|
173 |
|
174 #define BOOST_MEM_FN_NAME(X) X##_stdcall |
|
175 #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall |
|
176 #define BOOST_MEM_FN_CC __stdcall |
|
177 |
|
178 #include <boost/bind/mem_fn_vw.hpp> |
|
179 |
|
180 #undef BOOST_MEM_FN_NAME |
|
181 #undef BOOST_MEM_FN_NAME2 |
|
182 #undef BOOST_MEM_FN_CC |
|
183 |
|
184 #endif |
|
185 |
|
186 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL |
|
187 |
|
188 #define BOOST_MEM_FN_NAME(X) X##_fastcall |
|
189 #define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall |
|
190 #define BOOST_MEM_FN_CC __fastcall |
|
191 |
|
192 #include <boost/bind/mem_fn_vw.hpp> |
|
193 |
|
194 #undef BOOST_MEM_FN_NAME |
|
195 #undef BOOST_MEM_FN_NAME2 |
|
196 #undef BOOST_MEM_FN_CC |
|
197 |
|
198 #endif |
|
199 |
|
200 } // namespace _mfi |
|
201 |
|
202 #else // #ifdef BOOST_NO_VOID_RETURNS |
|
203 |
|
204 #define BOOST_MEM_FN_CLASS_F |
|
205 #define BOOST_MEM_FN_TYPEDEF(X) typedef X; |
|
206 |
|
207 namespace _mfi |
|
208 { |
|
209 |
|
210 #define BOOST_MEM_FN_RETURN return |
|
211 |
|
212 #define BOOST_MEM_FN_NAME(X) X |
|
213 #define BOOST_MEM_FN_CC |
|
214 |
|
215 #include <boost/bind/mem_fn_template.hpp> |
|
216 |
|
217 #undef BOOST_MEM_FN_CC |
|
218 #undef BOOST_MEM_FN_NAME |
|
219 |
|
220 #ifdef BOOST_MEM_FN_ENABLE_CDECL |
|
221 |
|
222 #define BOOST_MEM_FN_NAME(X) X##_cdecl |
|
223 #define BOOST_MEM_FN_CC __cdecl |
|
224 |
|
225 #include <boost/bind/mem_fn_template.hpp> |
|
226 |
|
227 #undef BOOST_MEM_FN_CC |
|
228 #undef BOOST_MEM_FN_NAME |
|
229 |
|
230 #endif |
|
231 |
|
232 #ifdef BOOST_MEM_FN_ENABLE_STDCALL |
|
233 |
|
234 #define BOOST_MEM_FN_NAME(X) X##_stdcall |
|
235 #define BOOST_MEM_FN_CC __stdcall |
|
236 |
|
237 #include <boost/bind/mem_fn_template.hpp> |
|
238 |
|
239 #undef BOOST_MEM_FN_CC |
|
240 #undef BOOST_MEM_FN_NAME |
|
241 |
|
242 #endif |
|
243 |
|
244 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL |
|
245 |
|
246 #define BOOST_MEM_FN_NAME(X) X##_fastcall |
|
247 #define BOOST_MEM_FN_CC __fastcall |
|
248 |
|
249 #include <boost/bind/mem_fn_template.hpp> |
|
250 |
|
251 #undef BOOST_MEM_FN_CC |
|
252 #undef BOOST_MEM_FN_NAME |
|
253 |
|
254 #endif |
|
255 |
|
256 #undef BOOST_MEM_FN_RETURN |
|
257 |
|
258 } // namespace _mfi |
|
259 |
|
260 #undef BOOST_MEM_FN_CLASS_F |
|
261 #undef BOOST_MEM_FN_TYPEDEF |
|
262 |
|
263 #endif // #ifdef BOOST_NO_VOID_RETURNS |
|
264 |
|
265 #define BOOST_MEM_FN_NAME(X) X |
|
266 #define BOOST_MEM_FN_CC |
|
267 |
|
268 #include <boost/bind/mem_fn_cc.hpp> |
|
269 |
|
270 #undef BOOST_MEM_FN_NAME |
|
271 #undef BOOST_MEM_FN_CC |
|
272 |
|
273 #ifdef BOOST_MEM_FN_ENABLE_CDECL |
|
274 |
|
275 #define BOOST_MEM_FN_NAME(X) X##_cdecl |
|
276 #define BOOST_MEM_FN_CC __cdecl |
|
277 |
|
278 #include <boost/bind/mem_fn_cc.hpp> |
|
279 |
|
280 #undef BOOST_MEM_FN_NAME |
|
281 #undef BOOST_MEM_FN_CC |
|
282 |
|
283 #endif |
|
284 |
|
285 #ifdef BOOST_MEM_FN_ENABLE_STDCALL |
|
286 |
|
287 #define BOOST_MEM_FN_NAME(X) X##_stdcall |
|
288 #define BOOST_MEM_FN_CC __stdcall |
|
289 |
|
290 #include <boost/bind/mem_fn_cc.hpp> |
|
291 |
|
292 #undef BOOST_MEM_FN_NAME |
|
293 #undef BOOST_MEM_FN_CC |
|
294 |
|
295 #endif |
|
296 |
|
297 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL |
|
298 |
|
299 #define BOOST_MEM_FN_NAME(X) X##_fastcall |
|
300 #define BOOST_MEM_FN_CC __fastcall |
|
301 |
|
302 #include <boost/bind/mem_fn_cc.hpp> |
|
303 |
|
304 #undef BOOST_MEM_FN_NAME |
|
305 #undef BOOST_MEM_FN_CC |
|
306 |
|
307 #endif |
|
308 |
|
309 // data member support |
|
310 |
|
311 namespace _mfi |
|
312 { |
|
313 |
|
314 template<class R, class T> class dm |
|
315 { |
|
316 public: |
|
317 |
|
318 typedef R const & result_type; |
|
319 typedef T const * argument_type; |
|
320 |
|
321 private: |
|
322 |
|
323 typedef R (T::*F); |
|
324 F f_; |
|
325 |
|
326 template<class U> R const & call(U & u, T const *) const |
|
327 { |
|
328 return (u.*f_); |
|
329 } |
|
330 |
|
331 template<class U> R const & call(U & u, void const *) const |
|
332 { |
|
333 return (get_pointer(u)->*f_); |
|
334 } |
|
335 |
|
336 public: |
|
337 |
|
338 explicit dm(F f): f_(f) {} |
|
339 |
|
340 R & operator()(T * p) const |
|
341 { |
|
342 return (p->*f_); |
|
343 } |
|
344 |
|
345 R const & operator()(T const * p) const |
|
346 { |
|
347 return (p->*f_); |
|
348 } |
|
349 |
|
350 template<class U> R const & operator()(U const & u) const |
|
351 { |
|
352 return call(u, &u); |
|
353 } |
|
354 |
|
355 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200) |
|
356 |
|
357 R & operator()(T & t) const |
|
358 { |
|
359 return (t.*f_); |
|
360 } |
|
361 |
|
362 R const & operator()(T const & t) const |
|
363 { |
|
364 return (t.*f_); |
|
365 } |
|
366 |
|
367 #endif |
|
368 |
|
369 bool operator==(dm const & rhs) const |
|
370 { |
|
371 return f_ == rhs.f_; |
|
372 } |
|
373 |
|
374 bool operator!=(dm const & rhs) const |
|
375 { |
|
376 return f_ != rhs.f_; |
|
377 } |
|
378 }; |
|
379 |
|
380 } // namespace _mfi |
|
381 |
|
382 template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f) |
|
383 { |
|
384 return _mfi::dm<R, T>(f); |
|
385 } |
|
386 |
|
387 } // namespace boost |
|
388 |
|
389 #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED |