Chris@16
|
1 // - lambda_traits.hpp --- Boost Lambda Library ----------------------------
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // For more information, see www.boost.org
|
Chris@16
|
10 // -------------------------------------------------------------------------
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_LAMBDA_LAMBDA_TRAITS_HPP
|
Chris@16
|
13 #define BOOST_LAMBDA_LAMBDA_TRAITS_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include "boost/type_traits/transform_traits.hpp"
|
Chris@16
|
16 #include "boost/type_traits/cv_traits.hpp"
|
Chris@16
|
17 #include "boost/type_traits/function_traits.hpp"
|
Chris@16
|
18 #include "boost/type_traits/object_traits.hpp"
|
Chris@16
|
19 #include "boost/tuple/tuple.hpp"
|
Chris@16
|
20
|
Chris@16
|
21 namespace boost {
|
Chris@16
|
22 namespace lambda {
|
Chris@16
|
23
|
Chris@16
|
24 // -- if construct ------------------------------------------------
|
Chris@16
|
25 // Proposed by Krzysztof Czarnecki and Ulrich Eisenecker
|
Chris@16
|
26
|
Chris@16
|
27 namespace detail {
|
Chris@16
|
28
|
Chris@16
|
29 template <bool If, class Then, class Else> struct IF { typedef Then RET; };
|
Chris@16
|
30
|
Chris@16
|
31 template <class Then, class Else> struct IF<false, Then, Else> {
|
Chris@16
|
32 typedef Else RET;
|
Chris@16
|
33 };
|
Chris@16
|
34
|
Chris@16
|
35
|
Chris@16
|
36 // An if construct that doesn't instantiate the non-matching template:
|
Chris@16
|
37
|
Chris@16
|
38 // Called as:
|
Chris@16
|
39 // IF_type<condition, A, B>::type
|
Chris@16
|
40 // The matching template must define the typeded 'type'
|
Chris@16
|
41 // I.e. A::type if condition is true, B::type if condition is false
|
Chris@16
|
42 // Idea from Vesa Karvonen (from C&E as well I guess)
|
Chris@16
|
43 template<class T>
|
Chris@16
|
44 struct IF_type_
|
Chris@16
|
45 {
|
Chris@16
|
46 typedef typename T::type type;
|
Chris@16
|
47 };
|
Chris@16
|
48
|
Chris@16
|
49
|
Chris@16
|
50 template<bool C, class T, class E>
|
Chris@16
|
51 struct IF_type
|
Chris@16
|
52 {
|
Chris@16
|
53 typedef typename
|
Chris@16
|
54 IF_type_<typename IF<C, T, E>::RET >::type type;
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 // helper that can be used to give typedef T to some type
|
Chris@16
|
58 template <class T> struct identity_mapping { typedef T type; };
|
Chris@16
|
59
|
Chris@16
|
60 // An if construct for finding an integral constant 'value'
|
Chris@16
|
61 // Does not instantiate the non-matching branch
|
Chris@16
|
62 // Called as IF_value<condition, A, B>::value
|
Chris@16
|
63 // If condition is true A::value must be defined, otherwise B::value
|
Chris@16
|
64
|
Chris@16
|
65 template<class T>
|
Chris@16
|
66 struct IF_value_
|
Chris@16
|
67 {
|
Chris@16
|
68 BOOST_STATIC_CONSTANT(int, value = T::value);
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71
|
Chris@16
|
72 template<bool C, class T, class E>
|
Chris@16
|
73 struct IF_value
|
Chris@16
|
74 {
|
Chris@16
|
75 BOOST_STATIC_CONSTANT(int, value = (IF_value_<typename IF<C, T, E>::RET>::value));
|
Chris@16
|
76 };
|
Chris@16
|
77
|
Chris@16
|
78
|
Chris@16
|
79 // --------------------------------------------------------------
|
Chris@16
|
80
|
Chris@16
|
81 // removes reference from other than function types:
|
Chris@16
|
82 template<class T> class remove_reference_if_valid
|
Chris@16
|
83 {
|
Chris@16
|
84
|
Chris@16
|
85 typedef typename boost::remove_reference<T>::type plainT;
|
Chris@16
|
86 public:
|
Chris@16
|
87 typedef typename IF<
|
Chris@16
|
88 boost::is_function<plainT>::value,
|
Chris@16
|
89 T,
|
Chris@16
|
90 plainT
|
Chris@16
|
91 >::RET type;
|
Chris@16
|
92
|
Chris@16
|
93 };
|
Chris@16
|
94
|
Chris@16
|
95
|
Chris@16
|
96 template<class T> struct remove_reference_and_cv {
|
Chris@16
|
97 typedef typename boost::remove_cv<
|
Chris@16
|
98 typename boost::remove_reference<T>::type
|
Chris@16
|
99 >::type type;
|
Chris@16
|
100 };
|
Chris@16
|
101
|
Chris@16
|
102
|
Chris@16
|
103
|
Chris@16
|
104 // returns a reference to the element of tuple T
|
Chris@16
|
105 template<int N, class T> struct tuple_element_as_reference {
|
Chris@16
|
106 typedef typename
|
Chris@16
|
107 boost::tuples::access_traits<
|
Chris@16
|
108 typename boost::tuples::element<N, T>::type
|
Chris@16
|
109 >::non_const_type type;
|
Chris@16
|
110 };
|
Chris@16
|
111
|
Chris@16
|
112 // returns the cv and reverence stripped type of a tuple element
|
Chris@16
|
113 template<int N, class T> struct tuple_element_stripped {
|
Chris@16
|
114 typedef typename
|
Chris@16
|
115 remove_reference_and_cv<
|
Chris@16
|
116 typename boost::tuples::element<N, T>::type
|
Chris@16
|
117 >::type type;
|
Chris@16
|
118 };
|
Chris@16
|
119
|
Chris@16
|
120 // is_lambda_functor -------------------------------------------------
|
Chris@16
|
121
|
Chris@16
|
122 template <class T> struct is_lambda_functor_ {
|
Chris@16
|
123 BOOST_STATIC_CONSTANT(bool, value = false);
|
Chris@16
|
124 };
|
Chris@16
|
125
|
Chris@16
|
126 template <class Arg> struct is_lambda_functor_<lambda_functor<Arg> > {
|
Chris@16
|
127 BOOST_STATIC_CONSTANT(bool, value = true);
|
Chris@16
|
128 };
|
Chris@16
|
129
|
Chris@16
|
130 } // end detail
|
Chris@16
|
131
|
Chris@16
|
132
|
Chris@16
|
133 template <class T> struct is_lambda_functor {
|
Chris@16
|
134 BOOST_STATIC_CONSTANT(bool,
|
Chris@16
|
135 value =
|
Chris@16
|
136 detail::is_lambda_functor_<
|
Chris@16
|
137 typename detail::remove_reference_and_cv<T>::type
|
Chris@16
|
138 >::value);
|
Chris@16
|
139 };
|
Chris@16
|
140
|
Chris@16
|
141
|
Chris@16
|
142 namespace detail {
|
Chris@16
|
143
|
Chris@16
|
144 // -- parameter_traits_ ---------------------------------------------
|
Chris@16
|
145
|
Chris@16
|
146 // An internal parameter type traits class that respects
|
Chris@16
|
147 // the reference_wrapper class.
|
Chris@16
|
148
|
Chris@16
|
149 // The conversions performed are:
|
Chris@16
|
150 // references -> compile_time_error
|
Chris@16
|
151 // T1 -> T2,
|
Chris@16
|
152 // reference_wrapper<T> -> T&
|
Chris@16
|
153 // const array -> ref to const array
|
Chris@16
|
154 // array -> ref to array
|
Chris@16
|
155 // function -> ref to function
|
Chris@16
|
156
|
Chris@16
|
157 // ------------------------------------------------------------------------
|
Chris@16
|
158
|
Chris@16
|
159 template<class T1, class T2>
|
Chris@16
|
160 struct parameter_traits_ {
|
Chris@16
|
161 typedef T2 type;
|
Chris@16
|
162 };
|
Chris@16
|
163
|
Chris@16
|
164 // Do not instantiate with reference types
|
Chris@16
|
165 template<class T, class Any> struct parameter_traits_<T&, Any> {
|
Chris@16
|
166 typedef typename
|
Chris@16
|
167 generate_error<T&>::
|
Chris@16
|
168 parameter_traits_class_instantiated_with_reference_type type;
|
Chris@16
|
169 };
|
Chris@16
|
170
|
Chris@16
|
171 // Arrays can't be stored as plain types; convert them to references
|
Chris@16
|
172 template<class T, int n, class Any> struct parameter_traits_<T[n], Any> {
|
Chris@16
|
173 typedef T (&type)[n];
|
Chris@16
|
174 };
|
Chris@16
|
175
|
Chris@16
|
176 template<class T, int n, class Any>
|
Chris@16
|
177 struct parameter_traits_<const T[n], Any> {
|
Chris@16
|
178 typedef const T (&type)[n];
|
Chris@16
|
179 };
|
Chris@16
|
180
|
Chris@16
|
181 template<class T, int n, class Any>
|
Chris@16
|
182 struct parameter_traits_<volatile T[n], Any> {
|
Chris@16
|
183 typedef volatile T (&type)[n];
|
Chris@16
|
184 };
|
Chris@16
|
185 template<class T, int n, class Any>
|
Chris@16
|
186 struct parameter_traits_<const volatile T[n], Any> {
|
Chris@16
|
187 typedef const volatile T (&type)[n];
|
Chris@16
|
188 };
|
Chris@16
|
189
|
Chris@16
|
190
|
Chris@16
|
191 template<class T, class Any>
|
Chris@16
|
192 struct parameter_traits_<boost::reference_wrapper<T>, Any >{
|
Chris@16
|
193 typedef T& type;
|
Chris@16
|
194 };
|
Chris@16
|
195
|
Chris@16
|
196 template<class T, class Any>
|
Chris@16
|
197 struct parameter_traits_<const boost::reference_wrapper<T>, Any >{
|
Chris@16
|
198 typedef T& type;
|
Chris@16
|
199 };
|
Chris@16
|
200
|
Chris@16
|
201 template<class T, class Any>
|
Chris@16
|
202 struct parameter_traits_<volatile boost::reference_wrapper<T>, Any >{
|
Chris@16
|
203 typedef T& type;
|
Chris@16
|
204 };
|
Chris@16
|
205
|
Chris@16
|
206 template<class T, class Any>
|
Chris@16
|
207 struct parameter_traits_<const volatile boost::reference_wrapper<T>, Any >{
|
Chris@16
|
208 typedef T& type;
|
Chris@16
|
209 };
|
Chris@16
|
210
|
Chris@16
|
211 template<class Any>
|
Chris@16
|
212 struct parameter_traits_<void, Any> {
|
Chris@16
|
213 typedef void type;
|
Chris@16
|
214 };
|
Chris@16
|
215
|
Chris@16
|
216 template<class Arg, class Any>
|
Chris@16
|
217 struct parameter_traits_<lambda_functor<Arg>, Any > {
|
Chris@16
|
218 typedef lambda_functor<Arg> type;
|
Chris@16
|
219 };
|
Chris@16
|
220
|
Chris@16
|
221 template<class Arg, class Any>
|
Chris@16
|
222 struct parameter_traits_<const lambda_functor<Arg>, Any > {
|
Chris@16
|
223 typedef lambda_functor<Arg> type;
|
Chris@16
|
224 };
|
Chris@16
|
225
|
Chris@16
|
226 // Are the volatile versions needed?
|
Chris@16
|
227 template<class Arg, class Any>
|
Chris@16
|
228 struct parameter_traits_<volatile lambda_functor<Arg>, Any > {
|
Chris@16
|
229 typedef lambda_functor<Arg> type;
|
Chris@16
|
230 };
|
Chris@16
|
231
|
Chris@16
|
232 template<class Arg, class Any>
|
Chris@16
|
233 struct parameter_traits_<const volatile lambda_functor<Arg>, Any > {
|
Chris@16
|
234 typedef lambda_functor<Arg> type;
|
Chris@16
|
235 };
|
Chris@16
|
236
|
Chris@16
|
237 } // end namespace detail
|
Chris@16
|
238
|
Chris@16
|
239
|
Chris@16
|
240 // ------------------------------------------------------------------------
|
Chris@16
|
241 // traits classes for lambda expressions (bind functions, operators ...)
|
Chris@16
|
242
|
Chris@16
|
243 // must be instantiated with non-reference types
|
Chris@16
|
244
|
Chris@16
|
245 // The default is const plain type -------------------------
|
Chris@16
|
246 // const T -> const T,
|
Chris@16
|
247 // T -> const T,
|
Chris@16
|
248 // references -> compile_time_error
|
Chris@16
|
249 // reference_wrapper<T> -> T&
|
Chris@16
|
250 // array -> const ref array
|
Chris@16
|
251 template<class T>
|
Chris@16
|
252 struct const_copy_argument {
|
Chris@16
|
253 typedef typename
|
Chris@16
|
254 detail::parameter_traits_<
|
Chris@16
|
255 T,
|
Chris@16
|
256 typename detail::IF<boost::is_function<T>::value, T&, const T>::RET
|
Chris@16
|
257 >::type type;
|
Chris@16
|
258 };
|
Chris@16
|
259
|
Chris@16
|
260 // T may be a function type. Without the IF test, const would be added
|
Chris@16
|
261 // to a function type, which is illegal.
|
Chris@16
|
262
|
Chris@16
|
263 // all arrays are converted to const.
|
Chris@16
|
264 // This traits template is used for 'const T&' parameter passing
|
Chris@16
|
265 // and thus the knowledge of the potential
|
Chris@16
|
266 // non-constness of an actual argument is lost.
|
Chris@16
|
267 template<class T, int n> struct const_copy_argument <T[n]> {
|
Chris@16
|
268 typedef const T (&type)[n];
|
Chris@16
|
269 };
|
Chris@16
|
270 template<class T, int n> struct const_copy_argument <volatile T[n]> {
|
Chris@16
|
271 typedef const volatile T (&type)[n];
|
Chris@16
|
272 };
|
Chris@16
|
273
|
Chris@16
|
274 template<class T>
|
Chris@16
|
275 struct const_copy_argument<T&> {};
|
Chris@16
|
276 // do not instantiate with references
|
Chris@16
|
277 // typedef typename detail::generate_error<T&>::references_not_allowed type;
|
Chris@16
|
278
|
Chris@16
|
279
|
Chris@16
|
280 template<>
|
Chris@16
|
281 struct const_copy_argument<void> {
|
Chris@16
|
282 typedef void type;
|
Chris@16
|
283 };
|
Chris@16
|
284
|
Chris@16
|
285
|
Chris@16
|
286 // Does the same as const_copy_argument, but passes references through as such
|
Chris@16
|
287 template<class T>
|
Chris@16
|
288 struct bound_argument_conversion {
|
Chris@16
|
289 typedef typename const_copy_argument<T>::type type;
|
Chris@16
|
290 };
|
Chris@16
|
291
|
Chris@16
|
292 template<class T>
|
Chris@16
|
293 struct bound_argument_conversion<T&> {
|
Chris@16
|
294 typedef T& type;
|
Chris@16
|
295 };
|
Chris@16
|
296
|
Chris@16
|
297 // The default is non-const reference -------------------------
|
Chris@16
|
298 // const T -> const T&,
|
Chris@16
|
299 // T -> T&,
|
Chris@16
|
300 // references -> compile_time_error
|
Chris@16
|
301 // reference_wrapper<T> -> T&
|
Chris@16
|
302 template<class T>
|
Chris@16
|
303 struct reference_argument {
|
Chris@16
|
304 typedef typename detail::parameter_traits_<T, T&>::type type;
|
Chris@16
|
305 };
|
Chris@16
|
306
|
Chris@16
|
307 template<class T>
|
Chris@16
|
308 struct reference_argument<T&> {
|
Chris@16
|
309 typedef typename detail::generate_error<T&>::references_not_allowed type;
|
Chris@16
|
310 };
|
Chris@16
|
311
|
Chris@16
|
312 template<class Arg>
|
Chris@16
|
313 struct reference_argument<lambda_functor<Arg> > {
|
Chris@16
|
314 typedef lambda_functor<Arg> type;
|
Chris@16
|
315 };
|
Chris@16
|
316
|
Chris@16
|
317 template<class Arg>
|
Chris@16
|
318 struct reference_argument<const lambda_functor<Arg> > {
|
Chris@16
|
319 typedef lambda_functor<Arg> type;
|
Chris@16
|
320 };
|
Chris@16
|
321
|
Chris@16
|
322 // Are the volatile versions needed?
|
Chris@16
|
323 template<class Arg>
|
Chris@16
|
324 struct reference_argument<volatile lambda_functor<Arg> > {
|
Chris@16
|
325 typedef lambda_functor<Arg> type;
|
Chris@16
|
326 };
|
Chris@16
|
327
|
Chris@16
|
328 template<class Arg>
|
Chris@16
|
329 struct reference_argument<const volatile lambda_functor<Arg> > {
|
Chris@16
|
330 typedef lambda_functor<Arg> type;
|
Chris@16
|
331 };
|
Chris@16
|
332
|
Chris@16
|
333 template<>
|
Chris@16
|
334 struct reference_argument<void> {
|
Chris@16
|
335 typedef void type;
|
Chris@16
|
336 };
|
Chris@16
|
337
|
Chris@16
|
338 namespace detail {
|
Chris@16
|
339
|
Chris@16
|
340 // Array to pointer conversion
|
Chris@16
|
341 template <class T>
|
Chris@16
|
342 struct array_to_pointer {
|
Chris@16
|
343 typedef T type;
|
Chris@16
|
344 };
|
Chris@16
|
345
|
Chris@16
|
346 template <class T, int N>
|
Chris@16
|
347 struct array_to_pointer <const T[N]> {
|
Chris@16
|
348 typedef const T* type;
|
Chris@16
|
349 };
|
Chris@16
|
350 template <class T, int N>
|
Chris@16
|
351 struct array_to_pointer <T[N]> {
|
Chris@16
|
352 typedef T* type;
|
Chris@16
|
353 };
|
Chris@16
|
354
|
Chris@16
|
355 template <class T, int N>
|
Chris@16
|
356 struct array_to_pointer <const T (&) [N]> {
|
Chris@16
|
357 typedef const T* type;
|
Chris@16
|
358 };
|
Chris@16
|
359 template <class T, int N>
|
Chris@16
|
360 struct array_to_pointer <T (&) [N]> {
|
Chris@16
|
361 typedef T* type;
|
Chris@16
|
362 };
|
Chris@16
|
363
|
Chris@16
|
364
|
Chris@16
|
365 // ---------------------------------------------------------------------------
|
Chris@16
|
366 // The call_traits for bind
|
Chris@16
|
367 // Respects the reference_wrapper class.
|
Chris@16
|
368
|
Chris@16
|
369 // These templates are used outside of bind functions as well.
|
Chris@16
|
370 // the bind_tuple_mapper provides a shorter notation for default
|
Chris@16
|
371 // bound argument storing semantics, if all arguments are treated
|
Chris@16
|
372 // uniformly.
|
Chris@16
|
373
|
Chris@16
|
374 // from template<class T> foo(const T& t) : bind_traits<const T>::type
|
Chris@16
|
375 // from template<class T> foo(T& t) : bind_traits<T>::type
|
Chris@16
|
376
|
Chris@16
|
377 // Conversions:
|
Chris@16
|
378 // T -> const T,
|
Chris@16
|
379 // cv T -> cv T,
|
Chris@16
|
380 // T& -> T&
|
Chris@16
|
381 // reference_wrapper<T> -> T&
|
Chris@16
|
382 // const reference_wrapper<T> -> T&
|
Chris@16
|
383 // array -> const ref array
|
Chris@16
|
384
|
Chris@16
|
385 // make bound arguments const, this is a deliberate design choice, the
|
Chris@16
|
386 // purpose is to prevent side effects to bound arguments that are stored
|
Chris@16
|
387 // as copies
|
Chris@16
|
388 template<class T>
|
Chris@16
|
389 struct bind_traits {
|
Chris@16
|
390 typedef const T type;
|
Chris@16
|
391 };
|
Chris@16
|
392
|
Chris@16
|
393 template<class T>
|
Chris@16
|
394 struct bind_traits<T&> {
|
Chris@16
|
395 typedef T& type;
|
Chris@16
|
396 };
|
Chris@16
|
397
|
Chris@16
|
398 // null_types are an exception, we always want to store them as non const
|
Chris@16
|
399 // so that other templates can assume that null_type is always without const
|
Chris@16
|
400 template<>
|
Chris@16
|
401 struct bind_traits<null_type> {
|
Chris@16
|
402 typedef null_type type;
|
Chris@16
|
403 };
|
Chris@16
|
404
|
Chris@16
|
405 // the bind_tuple_mapper, bind_type_generators may
|
Chris@16
|
406 // introduce const to null_type
|
Chris@16
|
407 template<>
|
Chris@16
|
408 struct bind_traits<const null_type> {
|
Chris@16
|
409 typedef null_type type;
|
Chris@16
|
410 };
|
Chris@16
|
411
|
Chris@16
|
412 // Arrays can't be stored as plain types; convert them to references.
|
Chris@16
|
413 // All arrays are converted to const. This is because bind takes its
|
Chris@16
|
414 // parameters as const T& and thus the knowledge of the potential
|
Chris@16
|
415 // non-constness of actual argument is lost.
|
Chris@16
|
416 template<class T, int n> struct bind_traits <T[n]> {
|
Chris@16
|
417 typedef const T (&type)[n];
|
Chris@16
|
418 };
|
Chris@16
|
419
|
Chris@16
|
420 template<class T, int n>
|
Chris@16
|
421 struct bind_traits<const T[n]> {
|
Chris@16
|
422 typedef const T (&type)[n];
|
Chris@16
|
423 };
|
Chris@16
|
424
|
Chris@16
|
425 template<class T, int n> struct bind_traits<volatile T[n]> {
|
Chris@16
|
426 typedef const volatile T (&type)[n];
|
Chris@16
|
427 };
|
Chris@16
|
428
|
Chris@16
|
429 template<class T, int n>
|
Chris@16
|
430 struct bind_traits<const volatile T[n]> {
|
Chris@16
|
431 typedef const volatile T (&type)[n];
|
Chris@16
|
432 };
|
Chris@16
|
433
|
Chris@16
|
434 template<class R>
|
Chris@16
|
435 struct bind_traits<R()> {
|
Chris@16
|
436 typedef R(&type)();
|
Chris@16
|
437 };
|
Chris@16
|
438
|
Chris@16
|
439 template<class R, class Arg1>
|
Chris@16
|
440 struct bind_traits<R(Arg1)> {
|
Chris@16
|
441 typedef R(&type)(Arg1);
|
Chris@16
|
442 };
|
Chris@16
|
443
|
Chris@16
|
444 template<class R, class Arg1, class Arg2>
|
Chris@16
|
445 struct bind_traits<R(Arg1, Arg2)> {
|
Chris@16
|
446 typedef R(&type)(Arg1, Arg2);
|
Chris@16
|
447 };
|
Chris@16
|
448
|
Chris@16
|
449 template<class R, class Arg1, class Arg2, class Arg3>
|
Chris@16
|
450 struct bind_traits<R(Arg1, Arg2, Arg3)> {
|
Chris@16
|
451 typedef R(&type)(Arg1, Arg2, Arg3);
|
Chris@16
|
452 };
|
Chris@16
|
453
|
Chris@16
|
454 template<class R, class Arg1, class Arg2, class Arg3, class Arg4>
|
Chris@16
|
455 struct bind_traits<R(Arg1, Arg2, Arg3, Arg4)> {
|
Chris@16
|
456 typedef R(&type)(Arg1, Arg2, Arg3, Arg4);
|
Chris@16
|
457 };
|
Chris@16
|
458
|
Chris@16
|
459 template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5>
|
Chris@16
|
460 struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5)> {
|
Chris@16
|
461 typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5);
|
Chris@16
|
462 };
|
Chris@16
|
463
|
Chris@16
|
464 template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6>
|
Chris@16
|
465 struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)> {
|
Chris@16
|
466 typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
|
Chris@16
|
467 };
|
Chris@16
|
468
|
Chris@16
|
469 template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7>
|
Chris@16
|
470 struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)> {
|
Chris@16
|
471 typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7);
|
Chris@16
|
472 };
|
Chris@16
|
473
|
Chris@16
|
474 template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8>
|
Chris@16
|
475 struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)> {
|
Chris@16
|
476 typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8);
|
Chris@16
|
477 };
|
Chris@16
|
478
|
Chris@16
|
479 template<class R, class Arg1, class Arg2, class Arg3, class Arg4, class Arg5, class Arg6, class Arg7, class Arg8, class Arg9>
|
Chris@16
|
480 struct bind_traits<R(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9)> {
|
Chris@16
|
481 typedef R(&type)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9);
|
Chris@16
|
482 };
|
Chris@16
|
483
|
Chris@16
|
484 template<class T>
|
Chris@16
|
485 struct bind_traits<reference_wrapper<T> >{
|
Chris@16
|
486 typedef T& type;
|
Chris@16
|
487 };
|
Chris@16
|
488
|
Chris@16
|
489 template<class T>
|
Chris@16
|
490 struct bind_traits<const reference_wrapper<T> >{
|
Chris@16
|
491 typedef T& type;
|
Chris@16
|
492 };
|
Chris@16
|
493
|
Chris@16
|
494 template<>
|
Chris@16
|
495 struct bind_traits<void> {
|
Chris@16
|
496 typedef void type;
|
Chris@16
|
497 };
|
Chris@16
|
498
|
Chris@16
|
499
|
Chris@16
|
500
|
Chris@16
|
501 template <
|
Chris@16
|
502 class T0 = null_type, class T1 = null_type, class T2 = null_type,
|
Chris@16
|
503 class T3 = null_type, class T4 = null_type, class T5 = null_type,
|
Chris@16
|
504 class T6 = null_type, class T7 = null_type, class T8 = null_type,
|
Chris@16
|
505 class T9 = null_type
|
Chris@16
|
506 >
|
Chris@16
|
507 struct bind_tuple_mapper {
|
Chris@16
|
508 typedef
|
Chris@16
|
509 tuple<typename bind_traits<T0>::type,
|
Chris@16
|
510 typename bind_traits<T1>::type,
|
Chris@16
|
511 typename bind_traits<T2>::type,
|
Chris@16
|
512 typename bind_traits<T3>::type,
|
Chris@16
|
513 typename bind_traits<T4>::type,
|
Chris@16
|
514 typename bind_traits<T5>::type,
|
Chris@16
|
515 typename bind_traits<T6>::type,
|
Chris@16
|
516 typename bind_traits<T7>::type,
|
Chris@16
|
517 typename bind_traits<T8>::type,
|
Chris@16
|
518 typename bind_traits<T9>::type> type;
|
Chris@16
|
519 };
|
Chris@16
|
520
|
Chris@16
|
521 // bind_traits, except map const T& -> const T
|
Chris@16
|
522 // this is needed e.g. in currying. Const reference arguments can
|
Chris@16
|
523 // refer to temporaries, so it is not safe to store them as references.
|
Chris@16
|
524 template <class T> struct remove_const_reference {
|
Chris@16
|
525 typedef typename bind_traits<T>::type type;
|
Chris@16
|
526 };
|
Chris@16
|
527
|
Chris@16
|
528 template <class T> struct remove_const_reference<const T&> {
|
Chris@16
|
529 typedef const T type;
|
Chris@16
|
530 };
|
Chris@16
|
531
|
Chris@16
|
532
|
Chris@16
|
533 // maps the bind argument types to the resulting lambda functor type
|
Chris@16
|
534 template <
|
Chris@16
|
535 class T0 = null_type, class T1 = null_type, class T2 = null_type,
|
Chris@16
|
536 class T3 = null_type, class T4 = null_type, class T5 = null_type,
|
Chris@16
|
537 class T6 = null_type, class T7 = null_type, class T8 = null_type,
|
Chris@16
|
538 class T9 = null_type
|
Chris@16
|
539 >
|
Chris@16
|
540 class bind_type_generator {
|
Chris@16
|
541
|
Chris@16
|
542 typedef typename
|
Chris@16
|
543 detail::bind_tuple_mapper<
|
Chris@16
|
544 T0, T1, T2, T3, T4, T5, T6, T7, T8, T9
|
Chris@16
|
545 >::type args_t;
|
Chris@16
|
546
|
Chris@16
|
547 BOOST_STATIC_CONSTANT(int, nof_elems = boost::tuples::length<args_t>::value);
|
Chris@16
|
548
|
Chris@16
|
549 typedef
|
Chris@16
|
550 action<
|
Chris@16
|
551 nof_elems,
|
Chris@16
|
552 function_action<nof_elems>
|
Chris@16
|
553 > action_type;
|
Chris@16
|
554
|
Chris@16
|
555 public:
|
Chris@16
|
556 typedef
|
Chris@16
|
557 lambda_functor<
|
Chris@16
|
558 lambda_functor_base<
|
Chris@16
|
559 action_type,
|
Chris@16
|
560 args_t
|
Chris@16
|
561 >
|
Chris@16
|
562 > type;
|
Chris@16
|
563
|
Chris@16
|
564 };
|
Chris@16
|
565
|
Chris@16
|
566
|
Chris@16
|
567
|
Chris@16
|
568 } // detail
|
Chris@16
|
569
|
Chris@16
|
570 template <class T> inline const T& make_const(const T& t) { return t; }
|
Chris@16
|
571
|
Chris@16
|
572
|
Chris@16
|
573 } // end of namespace lambda
|
Chris@16
|
574 } // end of namespace boost
|
Chris@16
|
575
|
Chris@16
|
576
|
Chris@16
|
577
|
Chris@16
|
578 #endif // BOOST_LAMBDA_TRAITS_HPP
|