]> git.lyx.org Git - lyx.git/blob - boost/boost/mem_fn.hpp
complie fix
[lyx.git] / boost / boost / mem_fn.hpp
1 #ifndef BOOST_MEM_FN_HPP_INCLUDED
2 #define BOOST_MEM_FN_HPP_INCLUDED
3
4 #if _MSC_VER+0 >= 1020
5 #pragma once
6 #endif
7
8 //
9 //  mem_fn.hpp - a generalization of std::mem_fun[_ref]
10 //
11 //  Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
12 //  Copyright (c) 2001 David Abrahams
13 //
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.
18 //
19 //  See http://www.boost.org/libs/bind/mem_fn.html for documentation.
20 //
21
22 #include <boost/config.hpp>
23
24 namespace boost
25 {
26
27 // get_pointer(p) extracts a ->* capable pointer from p
28
29 template<class T> T * get_pointer(T * p)
30 {
31     return p;
32 }
33
34 // get_pointer(shared_ptr<T> const & p) has been moved to shared_ptr.hpp
35
36 #if defined(BOOST_NO_VOID_RETURNS)
37
38 #define BOOST_MEM_FN_CLASS_F , class F
39 #define BOOST_MEM_FN_TYPEDEF(X)
40
41 namespace _mfi // mem_fun_impl
42 {
43
44 template<class V> struct mf
45 {
46
47 #define BOOST_MEM_FN_RETURN return
48
49 #define BOOST_MEM_FN_NAME(X) inner_##X
50 #define BOOST_MEM_FN_CC
51
52 #include <boost/bind/mem_fn_template.hpp>
53
54 #undef BOOST_MEM_FN_CC
55 #undef BOOST_MEM_FN_NAME
56
57 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
58
59 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
60 #define BOOST_MEM_FN_CC __stdcall
61
62 #include <boost/bind/mem_fn_template.hpp>
63
64 #undef BOOST_MEM_FN_CC
65 #undef BOOST_MEM_FN_NAME
66
67 #endif
68
69 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
70
71 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
72 #define BOOST_MEM_FN_CC __fastcall
73
74 #include <boost/bind/mem_fn_template.hpp>
75
76 #undef BOOST_MEM_FN_CC
77 #undef BOOST_MEM_FN_NAME
78
79 #endif
80
81 #undef BOOST_MEM_FN_RETURN
82
83 }; // struct mf<V>
84
85 template<> struct mf<void>
86 {
87
88 #define BOOST_MEM_FN_RETURN
89
90 #define BOOST_MEM_FN_NAME(X) inner_##X
91 #define BOOST_MEM_FN_CC
92
93 #include <boost/bind/mem_fn_template.hpp>
94
95 #undef BOOST_MEM_FN_CC
96 #undef BOOST_MEM_FN_NAME
97
98 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
99
100 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
101 #define BOOST_MEM_FN_CC __stdcall
102
103 #include <boost/bind/mem_fn_template.hpp>
104
105 #undef BOOST_MEM_FN_CC
106 #undef BOOST_MEM_FN_NAME
107
108 #endif
109
110 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
111
112 #define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
113 #define BOOST_MEM_FN_CC __fastcall
114
115 #include <boost/bind/mem_fn_template.hpp>
116
117 #undef BOOST_MEM_FN_CC
118 #undef BOOST_MEM_FN_NAME
119
120 #endif
121
122 #undef BOOST_MEM_FN_RETURN
123
124 }; // struct mf<void>
125
126 #undef BOOST_MEM_FN_CLASS_F
127 #undef BOOST_MEM_FN_TYPEDEF_F
128
129 #define BOOST_MEM_FN_NAME(X) X
130 #define BOOST_MEM_FN_NAME2(X) inner_##X
131 #define BOOST_MEM_FN_CC
132
133 #include <boost/bind/mem_fn_vw.hpp>
134
135 #undef BOOST_MEM_FN_NAME
136 #undef BOOST_MEM_FN_NAME2
137 #undef BOOST_MEM_FN_CC
138
139 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
140
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
144
145 #include <boost/bind/mem_fn_vw.hpp>
146
147 #undef BOOST_MEM_FN_NAME
148 #undef BOOST_MEM_FN_NAME2
149 #undef BOOST_MEM_FN_CC
150
151 #endif
152
153 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
154
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
158
159 #include <boost/bind/mem_fn_vw.hpp>
160
161 #undef BOOST_MEM_FN_NAME
162 #undef BOOST_MEM_FN_NAME2
163 #undef BOOST_MEM_FN_CC
164
165 #endif
166
167 } // namespace _mfi
168
169 #else // #ifdef BOOST_NO_VOID_RETURNS
170
171 #define BOOST_MEM_FN_CLASS_F
172 #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
173
174 namespace _mfi
175 {
176
177 #define BOOST_MEM_FN_RETURN return
178
179 #define BOOST_MEM_FN_NAME(X) X
180 #define BOOST_MEM_FN_CC
181
182 #include <boost/bind/mem_fn_template.hpp>
183
184 #undef BOOST_MEM_FN_CC
185 #undef BOOST_MEM_FN_NAME
186
187 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
188
189 #define BOOST_MEM_FN_NAME(X) X##_stdcall
190 #define BOOST_MEM_FN_CC __stdcall
191
192 #include <boost/bind/mem_fn_template.hpp>
193
194 #undef BOOST_MEM_FN_CC
195 #undef BOOST_MEM_FN_NAME
196
197 #endif
198
199 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
200
201 #define BOOST_MEM_FN_NAME(X) X##_fastcall
202 #define BOOST_MEM_FN_CC __fastcall
203
204 #include <boost/bind/mem_fn_template.hpp>
205
206 #undef BOOST_MEM_FN_CC
207 #undef BOOST_MEM_FN_NAME
208
209 #endif
210
211 #undef BOOST_MEM_FN_RETURN
212
213 } // namespace _mfi
214
215 #undef BOOST_MEM_FN_CLASS_F
216 #undef BOOST_MEM_FN_TYPEDEF
217
218 #endif // #ifdef BOOST_NO_VOID_RETURNS
219
220 #define BOOST_MEM_FN_NAME(X) X
221 #define BOOST_MEM_FN_CC
222
223 #include <boost/bind/mem_fn_cc.hpp>
224
225 #undef BOOST_MEM_FN_NAME
226 #undef BOOST_MEM_FN_CC
227
228 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
229
230 #define BOOST_MEM_FN_NAME(X) X##_stdcall
231 #define BOOST_MEM_FN_CC __stdcall
232
233 #include <boost/bind/mem_fn_cc.hpp>
234
235 #undef BOOST_MEM_FN_NAME
236 #undef BOOST_MEM_FN_CC
237
238 #endif
239
240 #ifdef BOOST_MEM_FN_ENABLE_FASTCALL
241
242 #define BOOST_MEM_FN_NAME(X) X##_fastcall
243 #define BOOST_MEM_FN_CC __fastcall
244
245 #include <boost/bind/mem_fn_cc.hpp>
246
247 #undef BOOST_MEM_FN_NAME
248 #undef BOOST_MEM_FN_CC
249
250 #endif
251
252 // data member support
253
254 namespace _mfi
255 {
256
257 template<class R, class T> class dm
258 {
259 public:
260
261     typedef R const & result_type;
262     typedef T const * argument_type;
263
264 private:
265     
266     typedef R (T::*F);
267     F f_;
268
269     template<class U> R const & call(U & u, T const *) const
270     {
271         return (u.*f_);
272     }
273
274     template<class U> R & call(U & u, T *) const
275     {
276         return (u.*f_);
277     }
278
279     template<class U> R const & call(U & u, void const *) const
280     {
281         return (get_pointer(u)->*f_);
282     }
283
284 public:
285     
286     explicit dm(F f): f_(f) {}
287
288     R & operator()(T * p) const
289     {
290         return (p->*f_);
291     }
292
293     R const & operator()(T const * p) const
294     {
295         return (p->*f_);
296     }
297
298     template<class U> R const & operator()(U & u) const
299     {
300         return call(u, &u);
301     }
302
303 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300)
304
305     R & operator()(T & t) const
306     {
307         return (t.*f_);
308     }
309
310 #endif
311
312     R const & operator()(T const & t) const
313     {
314         return (t.*f_);
315     }
316 };
317
318 } // namespace _mfi
319
320 template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
321 {
322     return _mfi::dm<R, T>(f);
323 }
324
325 } // namespace boost
326
327 #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED