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