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 #undef BOOST_MEM_FN_RETURN
73 template<> struct mf<void>
76 #define BOOST_MEM_FN_RETURN
78 #define BOOST_MEM_FN_NAME(X) inner_##X
79 #define BOOST_MEM_FN_CC
81 #include <boost/bind/mem_fn_template.hpp>
83 #undef BOOST_MEM_FN_CC
84 #undef BOOST_MEM_FN_NAME
86 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
88 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
89 #define BOOST_MEM_FN_CC __stdcall
91 #include <boost/bind/mem_fn_template.hpp>
93 #undef BOOST_MEM_FN_CC
94 #undef BOOST_MEM_FN_NAME
98 #undef BOOST_MEM_FN_RETURN
100 }; // struct mf<void>
102 #undef BOOST_MEM_FN_CLASS_F
103 #undef BOOST_MEM_FN_TYPEDEF_F
105 #define BOOST_MEM_FN_NAME(X) X
106 #define BOOST_MEM_FN_NAME2(X) inner_##X
107 #define BOOST_MEM_FN_CC
109 #include <boost/bind/mem_fn_vw.hpp>
111 #undef BOOST_MEM_FN_NAME
112 #undef BOOST_MEM_FN_NAME2
113 #undef BOOST_MEM_FN_CC
115 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
117 #define BOOST_MEM_FN_NAME(X) X##_stdcall
118 #define BOOST_MEM_FN_NAME2(X) inner_##X##_stdcall
119 #define BOOST_MEM_FN_CC __stdcall
121 #include <boost/bind/mem_fn_vw.hpp>
123 #undef BOOST_MEM_FN_NAME
124 #undef BOOST_MEM_FN_NAME2
125 #undef BOOST_MEM_FN_CC
131 #else // #ifdef BOOST_NO_VOID_RETURNS
133 #define BOOST_MEM_FN_CLASS_F
134 #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
139 #define BOOST_MEM_FN_RETURN return
141 #define BOOST_MEM_FN_NAME(X) X
142 #define BOOST_MEM_FN_CC
144 #include <boost/bind/mem_fn_template.hpp>
146 #undef BOOST_MEM_FN_CC
147 #undef BOOST_MEM_FN_NAME
149 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
151 #define BOOST_MEM_FN_NAME(X) X##_stdcall
152 #define BOOST_MEM_FN_CC __stdcall
154 #include <boost/bind/mem_fn_template.hpp>
156 #undef BOOST_MEM_FN_CC
157 #undef BOOST_MEM_FN_NAME
161 #undef BOOST_MEM_FN_RETURN
165 #undef BOOST_MEM_FN_CLASS_F
166 #undef BOOST_MEM_FN_TYPEDEF
168 #endif // #ifdef BOOST_NO_VOID_RETURNS
170 #define BOOST_MEM_FN_NAME(X) X
171 #define BOOST_MEM_FN_CC
173 #include <boost/bind/mem_fn_cc.hpp>
175 #undef BOOST_MEM_FN_NAME
176 #undef BOOST_MEM_FN_CC
178 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
180 #define BOOST_MEM_FN_NAME(X) X##_stdcall
181 #define BOOST_MEM_FN_CC __stdcall
183 #include <boost/bind/mem_fn_cc.hpp>
185 #undef BOOST_MEM_FN_NAME
186 #undef BOOST_MEM_FN_CC
190 // data member support
195 template<class R, class T> class dm
199 typedef R const & result_type;
200 typedef T const * argument_type;
207 template<class U> R const & call(U & u, T const *) const
212 template<class U> R & call(U & u, T *) const
217 template<class U> R const & call(U & u, void const *) const
219 return (get_pointer(u)->*f_);
224 explicit dm(F f): f_(f) {}
226 R & operator()(T * p) const
231 R const & operator()(T const * p) const
236 template<class U> R const & operator()(U & u) const
241 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300)
243 R & operator()(T & t) const
250 R const & operator()(T const & t) const
258 template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
260 return _mfi::dm<R, T>(f);
265 #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED