]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/spirit/home/classic/phoenix/functions.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / spirit / home / classic / phoenix / functions.hpp
1 /*=============================================================================
2 Phoenix V1.2.1
3 Copyright (c) 2001-2002 Joel de Guzman
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #ifndef PHOENIX_FUNCTIONS_HPP
9 #define PHOENIX_FUNCTIONS_HPP
10
11 ///////////////////////////////////////////////////////////////////////////////
12 #include <boost/spirit/home/classic/phoenix/actor.hpp>
13 #include <boost/spirit/home/classic/phoenix/composite.hpp>
14
15 ///////////////////////////////////////////////////////////////////////////////
16 namespace phoenix {
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //
20 // function class
21 //
22 // Lazy functions
23 //
24 // This class provides a mechanism for lazily evaluating functions.
25 // Syntactically, a lazy function looks like an ordinary C/C++
26 // function. The function call looks the same. However, unlike
27 // ordinary functions, the actual function execution is deferred.
28 // (see actor.hpp, primitives.hpp and composite.hpp for an
29 // overview). For example here are sample factorial function calls:
30 //
31 // factorial(4)
32 // factorial(arg1)
33 // factorial(arg1 * 6)
34 //
35 // These functions are automatically lazily bound unlike ordinary
36 // function pointers or functor objects that need to be explicitly
37 // bound through the bind function (see binders.hpp).
38 //
39 // A lazy function works in conjunction with a user defined functor
40 // (as usual with a member operator()). Only special forms of
41 // functor objects are allowed. This is required to enable true
42 // polymorphism (STL style monomorphic functors and function
43 // pointers can still be used through the bind facility in
44 // binders.hpp).
45 //
46 // This special functor is expected to have a nested template class
47 // result<A...TN> (where N is the number of arguments of its
48 // member operator()). The nested template class result should have
49 // a typedef 'type' that reflects the return type of its member
50 // operator(). This is essentially a type computer that answers the
51 // metaprogramming question "Given arguments of type A...TN, what
52 // will be the operator()'s return type?".
53 //
54 // There is a special case for functors that accept no arguments.
55 // Such nullary functors are only required to define a typedef
56 // result_type that reflects the return type of its operator().
57 //
58 // Here's an example of a simple functor that computes the
59 // factorial of a number:
60 //
61 // struct factorial_impl {
62 //
63 // template <typename Arg>
64 // struct result { typedef Arg type; };
65 //
66 // template <typename Arg>
67 // Arg operator()(Arg n) const
68 // { return (n <= 0) ? 1 : n * this->operator()(n-1); }
69 // };
70 //
71 // As can be seen, the functor can be polymorphic. Its arguments
72 // and return type are not fixed to a particular type. The example
73 // above for example, can handle any type as long as it can carry
74 // out the required operations (i.e. <=, * and -).
75 //
76 // We can now declare and instantiate a lazy 'factorial' function:
77 //
78 // function<factorial_impl> factorial;
79 //
80 // Invoking a lazy function 'factorial' does not immediately
81 // execute the functor factorial_impl. Instead, a composite (see
82 // composite.hpp) object is created and returned to the caller.
83 // Example:
84 //
85 // factorial(arg1)
86 //
87 // does nothing more than return a composite. A second function
88 // call will invoke the actual factorial function. Example:
89 //
90 // int i = 4;
91 // cout << factorial(arg1)(i);
92 //
93 // will print out "24".
94 //
95 // Take note that in certain cases (e.g. for functors with state),
96 // an instance may be passed on to the constructor. Example:
97 //
98 // function<factorial_impl> factorial(ftor);
99 //
100 // where ftor is an instance of factorial_impl (this is not
101 // necessary in this case since factorial is a simple stateless
102 // functor). Take care though when using functors with state
103 // because the functors are taken in by value. It is best to keep
104 // the data manipulated by a functor outside the functor itself and
105 // keep a reference to this data inside the functor. Also, it is
106 // best to keep functors as small as possible.
107 //
108 ///////////////////////////////////////////////////////////////////////////////
109 template <typename OperationT>
110 struct function {
111
112 function() : op() {}
113 function(OperationT const& op_) : op(op_) {}
114
115 actor<composite<OperationT> >
116 operator()() const;
117
118 template <typename A>
119 typename impl::make_composite<OperationT, A>::type
120 operator()(A const& a) const;
121
122 template <typename A, typename B>
123 typename impl::make_composite<OperationT, A, B>::type
124 operator()(A const& a, B const& b) const;
125
126 template <typename A, typename B, typename C>
127 typename impl::make_composite<OperationT, A, B, C>::type
128 operator()(A const& a, B const& b, C const& c) const;
129
130 #if PHOENIX_LIMIT > 3
131
132 template <typename A, typename B, typename C, typename D>
133 typename impl::make_composite<OperationT, A, B, C, D>::type
134 operator()(A const& a, B const& b, C const& c, D const& d) const;
135
136 template <typename A, typename B, typename C, typename D, typename E>
137 typename impl::make_composite<
138 OperationT, A, B, C, D, E
139 >::type
140 operator()(
141 A const& a, B const& b, C const& c, D const& d, E const& e
142 ) const;
143
144 template <
145 typename A, typename B, typename C, typename D, typename E,
146 typename F
147 >
148 typename impl::make_composite<
149 OperationT, A, B, C, D, E, F
150 >::type
151 operator()(
152 A const& a, B const& b, C const& c, D const& d, E const& e,
153 F const& f
154 ) const;
155
156 #if PHOENIX_LIMIT > 6
157
158 template <
159 typename A, typename B, typename C, typename D, typename E,
160 typename F, typename G
161 >
162 typename impl::make_composite<
163 OperationT, A, B, C, D, E, F, G
164 >::type
165 operator()(
166 A const& a, B const& b, C const& c, D const& d, E const& e,
167 F const& f, G const& g
168 ) const;
169
170 template <
171 typename A, typename B, typename C, typename D, typename E,
172 typename F, typename G, typename H
173 >
174 typename impl::make_composite<
175 OperationT, A, B, C, D, E, F, G, H
176 >::type
177 operator()(
178 A const& a, B const& b, C const& c, D const& d, E const& e,
179 F const& f, G const& g, H const& h
180 ) const;
181
182 template <
183 typename A, typename B, typename C, typename D, typename E,
184 typename F, typename G, typename H, typename I
185 >
186 typename impl::make_composite<
187 OperationT, A, B, C, D, E, F, G, H, I
188 >::type
189 operator()(
190 A const& a, B const& b, C const& c, D const& d, E const& e,
191 F const& f, G const& g, H const& h, I const& i
192 ) const;
193
194 #if PHOENIX_LIMIT > 9
195
196 template <
197 typename A, typename B, typename C, typename D, typename E,
198 typename F, typename G, typename H, typename I, typename J
199 >
200 typename impl::make_composite<
201 OperationT, A, B, C, D, E, F, G, H, I, J
202 >::type
203 operator()(
204 A const& a, B const& b, C const& c, D const& d, E const& e,
205 F const& f, G const& g, H const& h, I const& i, J const& j
206 ) const;
207
208 template <
209 typename A, typename B, typename C, typename D, typename E,
210 typename F, typename G, typename H, typename I, typename J,
211 typename K
212 >
213 typename impl::make_composite<
214 OperationT, A, B, C, D, E, F, G, H, I, J, K
215 >::type
216 operator()(
217 A const& a, B const& b, C const& c, D const& d, E const& e,
218 F const& f, G const& g, H const& h, I const& i, J const& j,
219 K const& k
220 ) const;
221
222 template <
223 typename A, typename B, typename C, typename D, typename E,
224 typename F, typename G, typename H, typename I, typename J,
225 typename K, typename L
226 >
227 typename impl::make_composite<
228 OperationT, A, B, C, D, E, F, G, H, I, J, K, L
229 >::type
230 operator()(
231 A const& a, B const& b, C const& c, D const& d, E const& e,
232 F const& f, G const& g, H const& h, I const& i, J const& j,
233 K const& k, L const& l
234 ) const;
235
236 #if PHOENIX_LIMIT > 12
237
238 template <
239 typename A, typename B, typename C, typename D, typename E,
240 typename F, typename G, typename H, typename I, typename J,
241 typename K, typename L, typename M
242 >
243 typename impl::make_composite<
244 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M
245 >::type
246 operator()(
247 A const& a, B const& b, C const& c, D const& d, E const& e,
248 F const& f, G const& g, H const& h, I const& i, J const& j,
249 K const& k, L const& l, M const& m
250 ) const;
251
252 template <
253 typename A, typename B, typename C, typename D, typename E,
254 typename F, typename G, typename H, typename I, typename J,
255 typename K, typename L, typename M, typename N
256 >
257 typename impl::make_composite<
258 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M, N
259 >::type
260 operator()(
261 A const& a, B const& b, C const& c, D const& d, E const& e,
262 F const& f, G const& g, H const& h, I const& i, J const& j,
263 K const& k, L const& l, M const& m, N const& n
264 ) const;
265
266 template <
267 typename A, typename B, typename C, typename D, typename E,
268 typename F, typename G, typename H, typename I, typename J,
269 typename K, typename L, typename M, typename N, typename O
270 >
271 typename impl::make_composite<
272 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O
273 >::type
274 operator()(
275 A const& a, B const& b, C const& c, D const& d, E const& e,
276 F const& f, G const& g, H const& h, I const& i, J const& j,
277 K const& k, L const& l, M const& m, N const& n, O const& o
278 ) const;
279
280 #endif
281 #endif
282 #endif
283 #endif
284
285 OperationT op;
286 };
287
288 ///////////////////////////////////////////////////////////////////////////////
289 //
290 // function class implementation
291 //
292 ///////////////////////////////////////////////////////////////////////////////
293 template <typename OperationT>
294 inline actor<composite<OperationT> >
295 function<OperationT>::operator()() const
296 {
297 return actor<composite<OperationT> >(op);
298 }
299
300 //////////////////////////////////
301 template <typename OperationT>
302 template <typename A>
303 inline typename impl::make_composite<OperationT, A>::type
304 function<OperationT>::operator()(A const& a) const
305 {
306 typedef typename impl::make_composite<OperationT, A>::composite_type ret_t;
307 return ret_t
308 (
309 op,
310 as_actor<A>::convert(a)
311 );
312 }
313
314 //////////////////////////////////
315 template <typename OperationT>
316 template <typename A, typename B>
317 inline typename impl::make_composite<OperationT, A, B>::type
318 function<OperationT>::operator()(A const& a, B const& b) const
319 {
320 typedef
321 typename impl::make_composite<OperationT, A, B>::composite_type
322 ret_t;
323
324 return ret_t(
325 op,
326 as_actor<A>::convert(a),
327 as_actor<B>::convert(b)
328 );
329 }
330
331 //////////////////////////////////
332 template <typename OperationT>
333 template <typename A, typename B, typename C>
334 inline typename impl::make_composite<OperationT, A, B, C>::type
335 function<OperationT>::operator()(A const& a, B const& b, C const& c) const
336 {
337 typedef
338 typename impl::make_composite<OperationT, A, B, C>::composite_type
339 ret_t;
340
341 return ret_t(
342 op,
343 as_actor<A>::convert(a),
344 as_actor<B>::convert(b),
345 as_actor<C>::convert(c)
346 );
347 }
348
349 #if PHOENIX_LIMIT > 3
350 //////////////////////////////////
351 template <typename OperationT>
352 template <
353 typename A, typename B, typename C, typename D
354 >
355 inline typename impl::make_composite<
356 OperationT, A, B, C, D
357 >::type
358 function<OperationT>::operator()(
359 A const& a, B const& b, C const& c, D const& d
360 ) const
361 {
362 typedef typename impl::make_composite<
363 OperationT, A, B, C, D
364 >::composite_type ret_t;
365
366 return ret_t(
367 op,
368 as_actor<A>::convert(a),
369 as_actor<B>::convert(b),
370 as_actor<C>::convert(c),
371 as_actor<D>::convert(d)
372 );
373 }
374
375 //////////////////////////////////
376 template <typename OperationT>
377 template <
378 typename A, typename B, typename C, typename D, typename E
379 >
380 inline typename impl::make_composite<
381 OperationT, A, B, C, D, E
382 >::type
383 function<OperationT>::operator()(
384 A const& a, B const& b, C const& c, D const& d, E const& e
385 ) const
386 {
387 typedef typename impl::make_composite<
388 OperationT, A, B, C, D, E
389 >::composite_type ret_t;
390
391 return ret_t(
392 op,
393 as_actor<A>::convert(a),
394 as_actor<B>::convert(b),
395 as_actor<C>::convert(c),
396 as_actor<D>::convert(d),
397 as_actor<E>::convert(e)
398 );
399 }
400
401 //////////////////////////////////
402 template <typename OperationT>
403 template <
404 typename A, typename B, typename C, typename D, typename E,
405 typename F
406 >
407 inline typename impl::make_composite<
408 OperationT, A, B, C, D, E, F
409 >::type
410 function<OperationT>::operator()(
411 A const& a, B const& b, C const& c, D const& d, E const& e,
412 F const& f
413 ) const
414 {
415 typedef typename impl::make_composite<
416 OperationT, A, B, C, D, E, F
417 >::composite_type ret_t;
418
419 return ret_t(
420 op,
421 as_actor<A>::convert(a),
422 as_actor<B>::convert(b),
423 as_actor<C>::convert(c),
424 as_actor<D>::convert(d),
425 as_actor<E>::convert(e),
426 as_actor<F>::convert(f)
427 );
428 }
429
430 #if PHOENIX_LIMIT > 6
431
432 //////////////////////////////////
433 template <typename OperationT>
434 template <
435 typename A, typename B, typename C, typename D, typename E,
436 typename F, typename G
437 >
438 inline typename impl::make_composite<
439 OperationT, A, B, C, D, E, F, G
440 >::type
441 function<OperationT>::operator()(
442 A const& a, B const& b, C const& c, D const& d, E const& e,
443 F const& f, G const& g
444 ) const
445 {
446 typedef typename impl::make_composite<
447 OperationT, A, B, C, D, E, F, G
448 >::composite_type ret_t;
449
450 return ret_t(
451 op,
452 as_actor<A>::convert(a),
453 as_actor<B>::convert(b),
454 as_actor<C>::convert(c),
455 as_actor<D>::convert(d),
456 as_actor<E>::convert(e),
457 as_actor<F>::convert(f),
458 as_actor<G>::convert(g)
459 );
460 }
461
462 //////////////////////////////////
463 template <typename OperationT>
464 template <
465 typename A, typename B, typename C, typename D, typename E,
466 typename F, typename G, typename H
467 >
468 inline typename impl::make_composite<
469 OperationT, A, B, C, D, E, F, G, H
470 >::type
471 function<OperationT>::operator()(
472 A const& a, B const& b, C const& c, D const& d, E const& e,
473 F const& f, G const& g, H const& h
474 ) const
475 {
476 typedef typename impl::make_composite<
477 OperationT, A, B, C, D, E, F, G, H
478 >::composite_type ret_t;
479
480 return ret_t(
481 op,
482 as_actor<A>::convert(a),
483 as_actor<B>::convert(b),
484 as_actor<C>::convert(c),
485 as_actor<D>::convert(d),
486 as_actor<E>::convert(e),
487 as_actor<F>::convert(f),
488 as_actor<G>::convert(g),
489 as_actor<H>::convert(h)
490 );
491 }
492
493 //////////////////////////////////
494 template <typename OperationT>
495 template <
496 typename A, typename B, typename C, typename D, typename E,
497 typename F, typename G, typename H, typename I
498 >
499 inline typename impl::make_composite<
500 OperationT, A, B, C, D, E, F, G, H, I
501 >::type
502 function<OperationT>::operator()(
503 A const& a, B const& b, C const& c, D const& d, E const& e,
504 F const& f, G const& g, H const& h, I const& i
505 ) const
506 {
507 typedef typename impl::make_composite<
508 OperationT, A, B, C, D, E, F, G, H, I
509 >::composite_type ret_t;
510
511 return ret_t(
512 op,
513 as_actor<A>::convert(a),
514 as_actor<B>::convert(b),
515 as_actor<C>::convert(c),
516 as_actor<D>::convert(d),
517 as_actor<E>::convert(e),
518 as_actor<F>::convert(f),
519 as_actor<G>::convert(g),
520 as_actor<H>::convert(h),
521 as_actor<I>::convert(i)
522 );
523 }
524
525 #if PHOENIX_LIMIT > 9
526
527 //////////////////////////////////
528 template <typename OperationT>
529 template <
530 typename A, typename B, typename C, typename D, typename E,
531 typename F, typename G, typename H, typename I, typename J
532 >
533 inline typename impl::make_composite<
534 OperationT, A, B, C, D, E, F, G, H, I, J
535 >::type
536 function<OperationT>::operator()(
537 A const& a, B const& b, C const& c, D const& d, E const& e,
538 F const& f, G const& g, H const& h, I const& i, J const& j
539 ) const
540 {
541 typedef typename impl::make_composite<
542 OperationT, A, B, C, D, E, F, G, H, I, J
543 >::composite_type ret_t;
544
545 return ret_t(
546 op,
547 as_actor<A>::convert(a),
548 as_actor<B>::convert(b),
549 as_actor<C>::convert(c),
550 as_actor<D>::convert(d),
551 as_actor<E>::convert(e),
552 as_actor<F>::convert(f),
553 as_actor<G>::convert(g),
554 as_actor<H>::convert(h),
555 as_actor<I>::convert(i),
556 as_actor<J>::convert(j)
557 );
558 }
559
560 //////////////////////////////////
561 template <typename OperationT>
562 template <
563 typename A, typename B, typename C, typename D, typename E,
564 typename F, typename G, typename H, typename I, typename J,
565 typename K
566 >
567 inline typename impl::make_composite<
568 OperationT, A, B, C, D, E, F, G, H, I, J, K
569 >::type
570 function<OperationT>::operator()(
571 A const& a, B const& b, C const& c, D const& d, E const& e,
572 F const& f, G const& g, H const& h, I const& i, J const& j,
573 K const& k
574 ) const
575 {
576 typedef typename impl::make_composite<
577 OperationT, A, B, C, D, E, F, G, H, I, J, K
578 >::composite_type ret_t;
579
580 return ret_t(
581 op,
582 as_actor<A>::convert(a),
583 as_actor<B>::convert(b),
584 as_actor<C>::convert(c),
585 as_actor<D>::convert(d),
586 as_actor<E>::convert(e),
587 as_actor<F>::convert(f),
588 as_actor<G>::convert(g),
589 as_actor<H>::convert(h),
590 as_actor<I>::convert(i),
591 as_actor<J>::convert(j),
592 as_actor<K>::convert(k)
593 );
594 }
595
596 //////////////////////////////////
597 template <typename OperationT>
598 template <
599 typename A, typename B, typename C, typename D, typename E,
600 typename F, typename G, typename H, typename I, typename J,
601 typename K, typename L
602 >
603 inline typename impl::make_composite<
604 OperationT, A, B, C, D, E, F, G, H, I, J, K, L
605 >::type
606 function<OperationT>::operator()(
607 A const& a, B const& b, C const& c, D const& d, E const& e,
608 F const& f, G const& g, H const& h, I const& i, J const& j,
609 K const& k, L const& l
610 ) const
611 {
612 typedef typename impl::make_composite<
613 OperationT, A, B, C, D, E, F, G, H, I, J, K, L
614 >::composite_type ret_t;
615
616 return ret_t(
617 op,
618 as_actor<A>::convert(a),
619 as_actor<B>::convert(b),
620 as_actor<C>::convert(c),
621 as_actor<D>::convert(d),
622 as_actor<E>::convert(e),
623 as_actor<F>::convert(f),
624 as_actor<G>::convert(g),
625 as_actor<H>::convert(h),
626 as_actor<I>::convert(i),
627 as_actor<J>::convert(j),
628 as_actor<K>::convert(k),
629 as_actor<L>::convert(l)
630 );
631 }
632
633 #if PHOENIX_LIMIT > 12
634
635 //////////////////////////////////
636 template <typename OperationT>
637 template <
638 typename A, typename B, typename C, typename D, typename E,
639 typename F, typename G, typename H, typename I, typename J,
640 typename K, typename L, typename M
641 >
642 inline typename impl::make_composite<
643 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M
644 >::type
645 function<OperationT>::operator()(
646 A const& a, B const& b, C const& c, D const& d, E const& e,
647 F const& f, G const& g, H const& h, I const& i, J const& j,
648 K const& k, L const& l, M const& m
649 ) const
650 {
651 typedef typename impl::make_composite<
652 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M
653 >::composite_type ret_t;
654
655 return ret_t(
656 op,
657 as_actor<A>::convert(a),
658 as_actor<B>::convert(b),
659 as_actor<C>::convert(c),
660 as_actor<D>::convert(d),
661 as_actor<E>::convert(e),
662 as_actor<F>::convert(f),
663 as_actor<G>::convert(g),
664 as_actor<H>::convert(h),
665 as_actor<I>::convert(i),
666 as_actor<J>::convert(j),
667 as_actor<K>::convert(k),
668 as_actor<L>::convert(l),
669 as_actor<M>::convert(m)
670 );
671 }
672
673 //////////////////////////////////
674 template <typename OperationT>
675 template <
676 typename A, typename B, typename C, typename D, typename E,
677 typename F, typename G, typename H, typename I, typename J,
678 typename K, typename L, typename M, typename N
679 >
680 inline typename impl::make_composite<
681 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M, N
682 >::type
683 function<OperationT>::operator()(
684 A const& a, B const& b, C const& c, D const& d, E const& e,
685 F const& f, G const& g, H const& h, I const& i, J const& j,
686 K const& k, L const& l, M const& m, N const& n
687 ) const
688 {
689 typedef typename impl::make_composite<
690 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M, N
691 >::composite_type ret_t;
692
693 return ret_t(
694 op,
695 as_actor<A>::convert(a),
696 as_actor<B>::convert(b),
697 as_actor<C>::convert(c),
698 as_actor<D>::convert(d),
699 as_actor<E>::convert(e),
700 as_actor<F>::convert(f),
701 as_actor<G>::convert(g),
702 as_actor<H>::convert(h),
703 as_actor<I>::convert(i),
704 as_actor<J>::convert(j),
705 as_actor<K>::convert(k),
706 as_actor<L>::convert(l),
707 as_actor<M>::convert(m),
708 as_actor<N>::convert(n)
709 );
710 }
711
712 //////////////////////////////////
713 template <typename OperationT>
714 template <
715 typename A, typename B, typename C, typename D, typename E,
716 typename F, typename G, typename H, typename I, typename J,
717 typename K, typename L, typename M, typename N, typename O
718 >
719 inline typename impl::make_composite<
720 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O
721 >::type
722 function<OperationT>::operator()(
723 A const& a, B const& b, C const& c, D const& d, E const& e,
724 F const& f, G const& g, H const& h, I const& i, J const& j,
725 K const& k, L const& l, M const& m, N const& n, O const& o
726 ) const
727 {
728 typedef typename impl::make_composite<
729 OperationT, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O
730 >::composite_type ret_t;
731
732 return ret_t(
733 op,
734 as_actor<A>::convert(a),
735 as_actor<B>::convert(b),
736 as_actor<C>::convert(c),
737 as_actor<D>::convert(d),
738 as_actor<E>::convert(e),
739 as_actor<F>::convert(f),
740 as_actor<G>::convert(g),
741 as_actor<H>::convert(h),
742 as_actor<I>::convert(i),
743 as_actor<J>::convert(j),
744 as_actor<K>::convert(k),
745 as_actor<L>::convert(l),
746 as_actor<M>::convert(m),
747 as_actor<N>::convert(n),
748 as_actor<O>::convert(o)
749 );
750 }
751
752 #endif
753 #endif
754 #endif
755 #endif
756
757 ///////////////////////////////////////////////////////////////////////////////
758 } // namespace phoenix
759
760 #endif