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