1 #ifndef BOOST_MEM_FN_HPP_INCLUDED
2 #define BOOST_MEM_FN_HPP_INCLUDED
9 // mem_fn.hpp - a generalization of std::mem_fun[_ref]
11 // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
12 // Copyright (c) 2001 David Abrahams
14 // Permission to copy, use, modify, sell and distribute this software
15 // is granted provided this copyright notice appears in all copies.
16 // This software is provided "as is" without express or implied
17 // warranty, and with no claim as to its suitability for any purpose.
19 // See http://www.boost.org/libs/bind/mem_fn.html for documentation.
22 #include <boost/config.hpp>
27 // get_pointer(p) extracts a ->* capable pointer from p
29 template<class T> T * get_pointer(T * p)
34 // get_pointer(shared_ptr<T> const & p) has been moved to shared_ptr.hpp
36 #if defined(BOOST_NO_VOID_RETURNS)
38 #define BOOST_MEM_FN_CLASS_F , class F
39 #define BOOST_MEM_FN_TYPEDEF(X)
41 namespace _mfi // mem_fun_impl
44 template<class V> struct mf
47 #define BOOST_MEM_FN_RETURN return
49 #define BOOST_MEM_FN_NAME(X) inner_##X
50 #define BOOST_MEM_FN_CC
52 #include <boost/bind/mem_fn_template.hpp>
54 #undef BOOST_MEM_FN_CC
55 #undef BOOST_MEM_FN_NAME
57 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
59 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
60 #define BOOST_MEM_FN_CC __stdcall
62 #include <boost/bind/mem_fn_template.hpp>
64 #undef BOOST_MEM_FN_CC
65 #undef BOOST_MEM_FN_NAME
69 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
71 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
72 #define BOOST_MEM_FN_CC __fastcall
74 #include <boost/bind/mem_fn_template.hpp>
76 #undef BOOST_MEM_FN_CC
77 #undef BOOST_MEM_FN_NAME
81 #undef BOOST_MEM_FN_RETURN
85 template<> struct mf<void>
88 #define BOOST_MEM_FN_RETURN
90 #define BOOST_MEM_FN_NAME(X) inner_##X
91 #define BOOST_MEM_FN_CC
93 #include <boost/bind/mem_fn_template.hpp>
95 #undef BOOST_MEM_FN_CC
96 #undef BOOST_MEM_FN_NAME
98 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
100 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
101 #define BOOST_MEM_FN_CC __stdcall
103 #include <boost/bind/mem_fn_template.hpp>
105 #undef BOOST_MEM_FN_CC
106 #undef BOOST_MEM_FN_NAME
110 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
112 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
113 #define BOOST_MEM_FN_CC __fastcall
115 #include <boost/bind/mem_fn_template.hpp>
117 #undef BOOST_MEM_FN_CC
118 #undef BOOST_MEM_FN_NAME
122 #undef BOOST_MEM_FN_RETURN
124 }; // struct mf<void>
126 #undef BOOST_MEM_FN_CLASS_F
127 #undef BOOST_MEM_FN_TYPEDEF_F
129 #define BOOST_MEM_FN_NAME(X) X
130 #define BOOST_MEM_FN_NAME2(X) inner_##X
131 #define BOOST_MEM_FN_CC
133 #include <boost/bind/mem_fn_vw.hpp>
135 #undef BOOST_MEM_FN_NAME
136 #undef BOOST_MEM_FN_NAME2
137 #undef BOOST_MEM_FN_CC
139 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
141 #define BOOST_MEM_FN_NAME(X) X##_stdcall
142 #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall
143 #define BOOST_MEM_FN_CC __stdcall
145 #include <boost/bind/mem_fn_vw.hpp>
147 #undef BOOST_MEM_FN_NAME
148 #undef BOOST_MEM_FN_NAME2
149 #undef BOOST_MEM_FN_CC
153 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
155 #define BOOST_MEM_FN_NAME(X) X##_fastcall
156 #define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall
157 #define BOOST_MEM_FN_CC __fastcall
159 #include <boost/bind/mem_fn_vw.hpp>
161 #undef BOOST_MEM_FN_NAME
162 #undef BOOST_MEM_FN_NAME2
163 #undef BOOST_MEM_FN_CC
169 #else // #ifdef BOOST_NO_VOID_RETURNS
171 #define BOOST_MEM_FN_CLASS_F
172 #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
177 #define BOOST_MEM_FN_RETURN return
179 #define BOOST_MEM_FN_NAME(X) X
180 #define BOOST_MEM_FN_CC
182 #include <boost/bind/mem_fn_template.hpp>
184 #undef BOOST_MEM_FN_CC
185 #undef BOOST_MEM_FN_NAME
187 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
189 #define BOOST_MEM_FN_NAME(X) X##_stdcall
190 #define BOOST_MEM_FN_CC __stdcall
192 #include <boost/bind/mem_fn_template.hpp>
194 #undef BOOST_MEM_FN_CC
195 #undef BOOST_MEM_FN_NAME
199 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
201 #define BOOST_MEM_FN_NAME(X) X##_fastcall
202 #define BOOST_MEM_FN_CC __fastcall
204 #include <boost/bind/mem_fn_template.hpp>
206 #undef BOOST_MEM_FN_CC
207 #undef BOOST_MEM_FN_NAME
211 #undef BOOST_MEM_FN_RETURN
215 #undef BOOST_MEM_FN_CLASS_F
216 #undef BOOST_MEM_FN_TYPEDEF
218 #endif // #ifdef BOOST_NO_VOID_RETURNS
220 #define BOOST_MEM_FN_NAME(X) X
221 #define BOOST_MEM_FN_CC
223 #include <boost/bind/mem_fn_cc.hpp>
225 #undef BOOST_MEM_FN_NAME
226 #undef BOOST_MEM_FN_CC
228 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
230 #define BOOST_MEM_FN_NAME(X) X##_stdcall
231 #define BOOST_MEM_FN_CC __stdcall
233 #include <boost/bind/mem_fn_cc.hpp>
235 #undef BOOST_MEM_FN_NAME
236 #undef BOOST_MEM_FN_CC
240 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
242 #define BOOST_MEM_FN_NAME(X) X##_fastcall
243 #define BOOST_MEM_FN_CC __fastcall
245 #include <boost/bind/mem_fn_cc.hpp>
247 #undef BOOST_MEM_FN_NAME
248 #undef BOOST_MEM_FN_CC
252 // data member support
257 template<class R, class T> class dm
261 typedef R const & result_type;
262 typedef T const * argument_type;
269 template<class U> R const & call(U & u, T const *) const
274 template<class U> R & call(U & u, T *) const
279 template<class U> R const & call(U & u, void const *) const
281 return (get_pointer(u)->*f_);
286 explicit dm(F f): f_(f) {}
288 R & operator()(T * p) const
293 R const & operator()(T const * p) const
298 template<class U> R const & operator()(U & u) const
303 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300)
305 R & operator()(T & t) const
312 R const & operator()(T const & t) const
320 template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
322 return _mfi::dm<R, T>(f);
327 #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED