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