]> git.lyx.org Git - lyx.git/blob - boost/boost/mem_fn.hpp
leave formula when pressing end at the end of a formula (and similarly
[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 #undef BOOST_MEM_FN_RETURN
70
71 }; // struct mf<V>
72
73 template<> struct mf<void>
74 {
75
76 #define BOOST_MEM_FN_RETURN
77
78 #define BOOST_MEM_FN_NAME(X) inner_##X
79 #define BOOST_MEM_FN_CC
80
81 #include <boost/bind/mem_fn_template.hpp>
82
83 #undef BOOST_MEM_FN_CC
84 #undef BOOST_MEM_FN_NAME
85
86 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
87
88 #define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
89 #define BOOST_MEM_FN_CC __stdcall
90
91 #include <boost/bind/mem_fn_template.hpp>
92
93 #undef BOOST_MEM_FN_CC
94 #undef BOOST_MEM_FN_NAME
95
96 #endif
97
98 #undef BOOST_MEM_FN_RETURN
99
100 }; // struct mf<void>
101
102 #undef BOOST_MEM_FN_CLASS_F
103 #undef BOOST_MEM_FN_TYPEDEF_F
104
105 #define BOOST_MEM_FN_NAME(X) X
106 #define BOOST_MEM_FN_NAME2(X) inner_##X
107 #define BOOST_MEM_FN_CC
108
109 #include <boost/bind/mem_fn_vw.hpp>
110
111 #undef BOOST_MEM_FN_NAME
112 #undef BOOST_MEM_FN_NAME2
113 #undef BOOST_MEM_FN_CC
114
115 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
116
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
120
121 #include <boost/bind/mem_fn_vw.hpp>
122
123 #undef BOOST_MEM_FN_NAME
124 #undef BOOST_MEM_FN_NAME2
125 #undef BOOST_MEM_FN_CC
126
127 #endif
128
129 } // namespace _mfi
130
131 #else // #ifdef BOOST_NO_VOID_RETURNS
132
133 #define BOOST_MEM_FN_CLASS_F
134 #define BOOST_MEM_FN_TYPEDEF(X) typedef X;
135
136 namespace _mfi
137 {
138
139 #define BOOST_MEM_FN_RETURN return
140
141 #define BOOST_MEM_FN_NAME(X) X
142 #define BOOST_MEM_FN_CC
143
144 #include <boost/bind/mem_fn_template.hpp>
145
146 #undef BOOST_MEM_FN_CC
147 #undef BOOST_MEM_FN_NAME
148
149 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
150
151 #define BOOST_MEM_FN_NAME(X) X##_stdcall
152 #define BOOST_MEM_FN_CC __stdcall
153
154 #include <boost/bind/mem_fn_template.hpp>
155
156 #undef BOOST_MEM_FN_CC
157 #undef BOOST_MEM_FN_NAME
158
159 #endif
160
161 #undef BOOST_MEM_FN_RETURN
162
163 } // namespace _mfi
164
165 #undef BOOST_MEM_FN_CLASS_F
166 #undef BOOST_MEM_FN_TYPEDEF
167
168 #endif // #ifdef BOOST_NO_VOID_RETURNS
169
170 #define BOOST_MEM_FN_NAME(X) X
171 #define BOOST_MEM_FN_CC
172
173 #include <boost/bind/mem_fn_cc.hpp>
174
175 #undef BOOST_MEM_FN_NAME
176 #undef BOOST_MEM_FN_CC
177
178 #ifdef BOOST_MEM_FN_ENABLE_STDCALL
179
180 #define BOOST_MEM_FN_NAME(X) X##_stdcall
181 #define BOOST_MEM_FN_CC __stdcall
182
183 #include <boost/bind/mem_fn_cc.hpp>
184
185 #undef BOOST_MEM_FN_NAME
186 #undef BOOST_MEM_FN_CC
187
188 #endif
189
190 // data member support
191
192 namespace _mfi
193 {
194
195 template<class R, class T> class dm
196 {
197 public:
198
199     typedef R const & result_type;
200     typedef T const * argument_type;
201
202 private:
203     
204     typedef R (T::*F);
205     F f_;
206
207     template<class U> R const & call(U & u, T const *) const
208     {
209         return (u.*f_);
210     }
211
212     template<class U> R & call(U & u, T *) const
213     {
214         return (u.*f_);
215     }
216
217     template<class U> R const & call(U & u, void const *) const
218     {
219         return (get_pointer(u)->*f_);
220     }
221
222 public:
223     
224     explicit dm(F f): f_(f) {}
225
226     R & operator()(T * p) const
227     {
228         return (p->*f_);
229     }
230
231     R const & operator()(T const * p) const
232     {
233         return (p->*f_);
234     }
235
236     template<class U> R const & operator()(U & u) const
237     {
238         return call(u, &u);
239     }
240
241 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300)
242
243     R & operator()(T & t) const
244     {
245         return (t.*f_);
246     }
247
248 #endif
249
250     R const & operator()(T const & t) const
251     {
252         return (t.*f_);
253     }
254 };
255
256 } // namespace _mfi
257
258 template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
259 {
260     return _mfi::dm<R, T>(f);
261 }
262
263 } // namespace boost
264
265 #endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED