1 | #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED |
2 | #define BOOST_BIND_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 | #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64) |
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 | #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64) |
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 | #define BOOST_MEM_FN_NOEXCEPT |
268 | |
269 | #include <boost/bind/mem_fn_cc.hpp> |
270 | |
271 | #if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED ) |
272 | # undef BOOST_MEM_FN_NOEXCEPT |
273 | # define BOOST_MEM_FN_NOEXCEPT noexcept |
274 | # include <boost/bind/mem_fn_cc.hpp> |
275 | #endif |
276 | |
277 | #undef BOOST_MEM_FN_NAME |
278 | #undef BOOST_MEM_FN_CC |
279 | #undef BOOST_MEM_FN_NOEXCEPT |
280 | |
281 | #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64) |
282 | |
283 | #define BOOST_MEM_FN_NAME(X) X##_cdecl |
284 | #define BOOST_MEM_FN_CC __cdecl |
285 | #define BOOST_MEM_FN_NOEXCEPT |
286 | |
287 | #include <boost/bind/mem_fn_cc.hpp> |
288 | |
289 | #undef BOOST_MEM_FN_NAME |
290 | #undef BOOST_MEM_FN_CC |
291 | #undef BOOST_MEM_FN_NOEXCEPT |
292 | |
293 | #endif |
294 | |
295 | #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64) |
296 | |
297 | #define BOOST_MEM_FN_NAME(X) X##_stdcall |
298 | #define BOOST_MEM_FN_CC __stdcall |
299 | #define BOOST_MEM_FN_NOEXCEPT |
300 | |
301 | #include <boost/bind/mem_fn_cc.hpp> |
302 | |
303 | #undef BOOST_MEM_FN_NAME |
304 | #undef BOOST_MEM_FN_CC |
305 | #undef BOOST_MEM_FN_NOEXCEPT |
306 | |
307 | #endif |
308 | |
309 | #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64) |
310 | |
311 | #define BOOST_MEM_FN_NAME(X) X##_fastcall |
312 | #define BOOST_MEM_FN_CC __fastcall |
313 | #define BOOST_MEM_FN_NOEXCEPT |
314 | |
315 | #include <boost/bind/mem_fn_cc.hpp> |
316 | |
317 | #undef BOOST_MEM_FN_NAME |
318 | #undef BOOST_MEM_FN_CC |
319 | #undef BOOST_MEM_FN_NOEXCEPT |
320 | |
321 | #endif |
322 | |
323 | // data member support |
324 | |
325 | namespace _mfi |
326 | { |
327 | |
328 | template<class R, class T> class dm |
329 | { |
330 | public: |
331 | |
332 | typedef R const & result_type; |
333 | typedef T const * argument_type; |
334 | |
335 | private: |
336 | |
337 | typedef R (T::*F); |
338 | F f_; |
339 | |
340 | template<class U> R const & call(U & u, T const *) const |
341 | { |
342 | return (u.*f_); |
343 | } |
344 | |
345 | template<class U> R const & call(U & u, void const *) const |
346 | { |
347 | return (get_pointer(u)->*f_); |
348 | } |
349 | |
350 | public: |
351 | |
352 | explicit dm(F f): f_(f) {} |
353 | |
354 | R & operator()(T * p) const |
355 | { |
356 | return (p->*f_); |
357 | } |
358 | |
359 | R const & operator()(T const * p) const |
360 | { |
361 | return (p->*f_); |
362 | } |
363 | |
364 | template<class U> R const & operator()(U const & u) const |
365 | { |
366 | return call(u, &u); |
367 | } |
368 | |
369 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200) |
370 | |
371 | R & operator()(T & t) const |
372 | { |
373 | return (t.*f_); |
374 | } |
375 | |
376 | R const & operator()(T const & t) const |
377 | { |
378 | return (t.*f_); |
379 | } |
380 | |
381 | #endif |
382 | |
383 | bool operator==(dm const & rhs) const |
384 | { |
385 | return f_ == rhs.f_; |
386 | } |
387 | |
388 | bool operator!=(dm const & rhs) const |
389 | { |
390 | return f_ != rhs.f_; |
391 | } |
392 | }; |
393 | |
394 | } // namespace _mfi |
395 | |
396 | template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f) |
397 | { |
398 | return _mfi::dm<R, T>(f); |
399 | } |
400 | |
401 | } // namespace boost |
402 | |
403 | #endif // #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED |
404 | |