blob: b2a915e15a556cb6c1d4776823353ce40c0bddb6 [file] [log] [blame]
Jeff Thompson3d613fd2013-10-15 15:39:04 -07001#ifndef NDNBOOST_BIND_MEM_FN_HPP_INCLUDED
2#define NDNBOOST_BIND_MEM_FN_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07003
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 <ndnboost/config.hpp>
25#include <ndnboost/get_pointer.hpp>
26#include <ndnboost/detail/workaround.hpp>
27
28namespace ndnboost
29{
30
Jeff Thompson3d613fd2013-10-15 15:39:04 -070031#if defined(NDNBOOST_NO_VOID_RETURNS)
Jeff Thompsona28eed82013-08-22 16:21:10 -070032
Jeff Thompson3d613fd2013-10-15 15:39:04 -070033#define NDNBOOST_MEM_FN_CLASS_F , class F
34#define NDNBOOST_MEM_FN_TYPEDEF(X)
Jeff Thompsona28eed82013-08-22 16:21:10 -070035
36namespace _mfi // mem_fun_impl
37{
38
39template<class V> struct mf
40{
41
Jeff Thompson3d613fd2013-10-15 15:39:04 -070042#define NDNBOOST_MEM_FN_RETURN return
Jeff Thompsona28eed82013-08-22 16:21:10 -070043
Jeff Thompson3d613fd2013-10-15 15:39:04 -070044#define NDNBOOST_MEM_FN_NAME(X) inner_##X
45#define NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -070046
47#include <ndnboost/bind/mem_fn_template.hpp>
48
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049#undef NDNBOOST_MEM_FN_CC
50#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -070051
Jeff Thompson3d613fd2013-10-15 15:39:04 -070052#ifdef NDNBOOST_MEM_FN_ENABLE_CDECL
Jeff Thompsona28eed82013-08-22 16:21:10 -070053
Jeff Thompson3d613fd2013-10-15 15:39:04 -070054#define NDNBOOST_MEM_FN_NAME(X) inner_##X##_cdecl
55#define NDNBOOST_MEM_FN_CC __cdecl
Jeff Thompsona28eed82013-08-22 16:21:10 -070056
57#include <ndnboost/bind/mem_fn_template.hpp>
58
Jeff Thompson3d613fd2013-10-15 15:39:04 -070059#undef NDNBOOST_MEM_FN_CC
60#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -070061
62#endif
63
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064#ifdef NDNBOOST_MEM_FN_ENABLE_STDCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -070065
Jeff Thompson3d613fd2013-10-15 15:39:04 -070066#define NDNBOOST_MEM_FN_NAME(X) inner_##X##_stdcall
67#define NDNBOOST_MEM_FN_CC __stdcall
Jeff Thompsona28eed82013-08-22 16:21:10 -070068
69#include <ndnboost/bind/mem_fn_template.hpp>
70
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071#undef NDNBOOST_MEM_FN_CC
72#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -070073
74#endif
75
Jeff Thompson3d613fd2013-10-15 15:39:04 -070076#ifdef NDNBOOST_MEM_FN_ENABLE_FASTCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -070077
Jeff Thompson3d613fd2013-10-15 15:39:04 -070078#define NDNBOOST_MEM_FN_NAME(X) inner_##X##_fastcall
79#define NDNBOOST_MEM_FN_CC __fastcall
Jeff Thompsona28eed82013-08-22 16:21:10 -070080
81#include <ndnboost/bind/mem_fn_template.hpp>
82
Jeff Thompson3d613fd2013-10-15 15:39:04 -070083#undef NDNBOOST_MEM_FN_CC
84#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -070085
86#endif
87
Jeff Thompson3d613fd2013-10-15 15:39:04 -070088#undef NDNBOOST_MEM_FN_RETURN
Jeff Thompsona28eed82013-08-22 16:21:10 -070089
90}; // struct mf<V>
91
92template<> struct mf<void>
93{
94
Jeff Thompson3d613fd2013-10-15 15:39:04 -070095#define NDNBOOST_MEM_FN_RETURN
Jeff Thompsona28eed82013-08-22 16:21:10 -070096
Jeff Thompson3d613fd2013-10-15 15:39:04 -070097#define NDNBOOST_MEM_FN_NAME(X) inner_##X
98#define NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -070099
100#include <ndnboost/bind/mem_fn_template.hpp>
101
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700102#undef NDNBOOST_MEM_FN_CC
103#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700104
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105#ifdef NDNBOOST_MEM_FN_ENABLE_CDECL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700106
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700107#define NDNBOOST_MEM_FN_NAME(X) inner_##X##_cdecl
108#define NDNBOOST_MEM_FN_CC __cdecl
Jeff Thompsona28eed82013-08-22 16:21:10 -0700109
110#include <ndnboost/bind/mem_fn_template.hpp>
111
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700112#undef NDNBOOST_MEM_FN_CC
113#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700114
115#endif
116
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117#ifdef NDNBOOST_MEM_FN_ENABLE_STDCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700118
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700119#define NDNBOOST_MEM_FN_NAME(X) inner_##X##_stdcall
120#define NDNBOOST_MEM_FN_CC __stdcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700121
122#include <ndnboost/bind/mem_fn_template.hpp>
123
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700124#undef NDNBOOST_MEM_FN_CC
125#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700126
127#endif
128
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700129#ifdef NDNBOOST_MEM_FN_ENABLE_FASTCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700130
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700131#define NDNBOOST_MEM_FN_NAME(X) inner_##X##_fastcall
132#define NDNBOOST_MEM_FN_CC __fastcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700133
134#include <ndnboost/bind/mem_fn_template.hpp>
135
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700136#undef NDNBOOST_MEM_FN_CC
137#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700138
139#endif
140
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700141#undef NDNBOOST_MEM_FN_RETURN
Jeff Thompsona28eed82013-08-22 16:21:10 -0700142
143}; // struct mf<void>
144
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700145#undef NDNBOOST_MEM_FN_CLASS_F
146#undef NDNBOOST_MEM_FN_TYPEDEF_F
Jeff Thompsona28eed82013-08-22 16:21:10 -0700147
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700148#define NDNBOOST_MEM_FN_NAME(X) X
149#define NDNBOOST_MEM_FN_NAME2(X) inner_##X
150#define NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700151
152#include <ndnboost/bind/mem_fn_vw.hpp>
153
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700154#undef NDNBOOST_MEM_FN_NAME
155#undef NDNBOOST_MEM_FN_NAME2
156#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700157
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700158#ifdef NDNBOOST_MEM_FN_ENABLE_CDECL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700159
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700160#define NDNBOOST_MEM_FN_NAME(X) X##_cdecl
161#define NDNBOOST_MEM_FN_NAME2(X) inner_##X##_cdecl
162#define NDNBOOST_MEM_FN_CC __cdecl
Jeff Thompsona28eed82013-08-22 16:21:10 -0700163
164#include <ndnboost/bind/mem_fn_vw.hpp>
165
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700166#undef NDNBOOST_MEM_FN_NAME
167#undef NDNBOOST_MEM_FN_NAME2
168#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700169
170#endif
171
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700172#ifdef NDNBOOST_MEM_FN_ENABLE_STDCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700173
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700174#define NDNBOOST_MEM_FN_NAME(X) X##_stdcall
175#define NDNBOOST_MEM_FN_NAME2(X) inner_##X##_stdcall
176#define NDNBOOST_MEM_FN_CC __stdcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700177
178#include <ndnboost/bind/mem_fn_vw.hpp>
179
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700180#undef NDNBOOST_MEM_FN_NAME
181#undef NDNBOOST_MEM_FN_NAME2
182#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700183
184#endif
185
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700186#ifdef NDNBOOST_MEM_FN_ENABLE_FASTCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700187
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700188#define NDNBOOST_MEM_FN_NAME(X) X##_fastcall
189#define NDNBOOST_MEM_FN_NAME2(X) inner_##X##_fastcall
190#define NDNBOOST_MEM_FN_CC __fastcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700191
192#include <ndnboost/bind/mem_fn_vw.hpp>
193
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700194#undef NDNBOOST_MEM_FN_NAME
195#undef NDNBOOST_MEM_FN_NAME2
196#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700197
198#endif
199
200} // namespace _mfi
201
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700202#else // #ifdef NDNBOOST_NO_VOID_RETURNS
Jeff Thompsona28eed82013-08-22 16:21:10 -0700203
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700204#define NDNBOOST_MEM_FN_CLASS_F
205#define NDNBOOST_MEM_FN_TYPEDEF(X) typedef X;
Jeff Thompsona28eed82013-08-22 16:21:10 -0700206
207namespace _mfi
208{
209
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700210#define NDNBOOST_MEM_FN_RETURN return
Jeff Thompsona28eed82013-08-22 16:21:10 -0700211
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700212#define NDNBOOST_MEM_FN_NAME(X) X
213#define NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700214
215#include <ndnboost/bind/mem_fn_template.hpp>
216
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700217#undef NDNBOOST_MEM_FN_CC
218#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700219
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700220#ifdef NDNBOOST_MEM_FN_ENABLE_CDECL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700221
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700222#define NDNBOOST_MEM_FN_NAME(X) X##_cdecl
223#define NDNBOOST_MEM_FN_CC __cdecl
Jeff Thompsona28eed82013-08-22 16:21:10 -0700224
225#include <ndnboost/bind/mem_fn_template.hpp>
226
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700227#undef NDNBOOST_MEM_FN_CC
228#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700229
230#endif
231
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700232#ifdef NDNBOOST_MEM_FN_ENABLE_STDCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700233
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700234#define NDNBOOST_MEM_FN_NAME(X) X##_stdcall
235#define NDNBOOST_MEM_FN_CC __stdcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700236
237#include <ndnboost/bind/mem_fn_template.hpp>
238
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700239#undef NDNBOOST_MEM_FN_CC
240#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700241
242#endif
243
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700244#ifdef NDNBOOST_MEM_FN_ENABLE_FASTCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700245
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700246#define NDNBOOST_MEM_FN_NAME(X) X##_fastcall
247#define NDNBOOST_MEM_FN_CC __fastcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700248
249#include <ndnboost/bind/mem_fn_template.hpp>
250
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700251#undef NDNBOOST_MEM_FN_CC
252#undef NDNBOOST_MEM_FN_NAME
Jeff Thompsona28eed82013-08-22 16:21:10 -0700253
254#endif
255
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700256#undef NDNBOOST_MEM_FN_RETURN
Jeff Thompsona28eed82013-08-22 16:21:10 -0700257
258} // namespace _mfi
259
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700260#undef NDNBOOST_MEM_FN_CLASS_F
261#undef NDNBOOST_MEM_FN_TYPEDEF
Jeff Thompsona28eed82013-08-22 16:21:10 -0700262
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700263#endif // #ifdef NDNBOOST_NO_VOID_RETURNS
Jeff Thompsona28eed82013-08-22 16:21:10 -0700264
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700265#define NDNBOOST_MEM_FN_NAME(X) X
266#define NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700267
268#include <ndnboost/bind/mem_fn_cc.hpp>
269
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700270#undef NDNBOOST_MEM_FN_NAME
271#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700272
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700273#ifdef NDNBOOST_MEM_FN_ENABLE_CDECL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700274
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700275#define NDNBOOST_MEM_FN_NAME(X) X##_cdecl
276#define NDNBOOST_MEM_FN_CC __cdecl
Jeff Thompsona28eed82013-08-22 16:21:10 -0700277
278#include <ndnboost/bind/mem_fn_cc.hpp>
279
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700280#undef NDNBOOST_MEM_FN_NAME
281#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700282
283#endif
284
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700285#ifdef NDNBOOST_MEM_FN_ENABLE_STDCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700286
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700287#define NDNBOOST_MEM_FN_NAME(X) X##_stdcall
288#define NDNBOOST_MEM_FN_CC __stdcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700289
290#include <ndnboost/bind/mem_fn_cc.hpp>
291
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700292#undef NDNBOOST_MEM_FN_NAME
293#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700294
295#endif
296
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700297#ifdef NDNBOOST_MEM_FN_ENABLE_FASTCALL
Jeff Thompsona28eed82013-08-22 16:21:10 -0700298
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700299#define NDNBOOST_MEM_FN_NAME(X) X##_fastcall
300#define NDNBOOST_MEM_FN_CC __fastcall
Jeff Thompsona28eed82013-08-22 16:21:10 -0700301
302#include <ndnboost/bind/mem_fn_cc.hpp>
303
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700304#undef NDNBOOST_MEM_FN_NAME
305#undef NDNBOOST_MEM_FN_CC
Jeff Thompsona28eed82013-08-22 16:21:10 -0700306
307#endif
308
309// data member support
310
311namespace _mfi
312{
313
314template<class R, class T> class dm
315{
316public:
317
318 typedef R const & result_type;
319 typedef T const * argument_type;
320
321private:
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
336public:
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700355#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1300) && !NDNBOOST_WORKAROUND(__MWERKS__, < 0x3200)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700356
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
382template<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 ndnboost
388
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700389#endif // #ifndef NDNBOOST_BIND_MEM_FN_HPP_INCLUDED