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