1// -- algorithm.hpp -- Boost Lambda Library -----------------------------------
2// Copyright (C) 2002 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
3// Copyright (C) 2002 Gary Powell (gwpowell@hotmail.com)
4//
5// Distributed under the Boost Software License, Version 1.0. (See
6// accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// For more information, see http://www.boost.org
10
11#ifndef BOOST_LAMBDA_ALGORITHM_HPP
12#define BOOST_LAMBDA_ALGORITHM_HPP
13
14#include "boost/lambda/core.hpp"
15
16#include <algorithm>
17#include <iterator> // for iterator_traits
18#include <utility> // for std::pair
19
20namespace boost {
21 namespace lambda {
22
23namespace ll {
24
25// for_each ---------------------------------
26
27struct for_each {
28
29 template <class Args>
30 struct sig {
31 typedef typename boost::remove_const<
32 typename boost::tuples::element<3, Args>::type
33 >::type type;
34 };
35
36 template <class A, class C>
37 C
38 operator()(A a, A b, C c) const
39 { return ::std::for_each(a, b, c); }
40};
41
42// find ---------------------------------
43
44struct find {
45
46 template <class Args>
47 struct sig {
48 typedef typename boost::remove_const<
49 typename boost::tuples::element<1, Args>::type
50 >::type type;
51 };
52
53 template <class A, class C>
54 A
55 operator()(A a, A b, const C& c) const
56 { return ::std::find(a, b, c); }
57};
58
59
60// find_if ---------------------------------
61
62struct find_if {
63
64 template <class Args>
65 struct sig {
66 typedef typename boost::remove_const<
67 typename boost::tuples::element<1, Args>::type
68 >::type type;
69 };
70
71 template <class A, class C>
72 A
73 operator()(A a, A b, C c) const
74 { return ::std::find_if(a, b, c); }
75};
76
77// find_end ---------------------------------
78
79struct find_end {
80
81 template <class Args>
82 struct sig {
83 typedef typename boost::remove_const<
84 typename boost::tuples::element<1, Args>::type
85 >::type type;
86 };
87
88 template <class A, class C>
89 A
90 operator()(A a, A b, C c, C d) const
91 { return ::std::find_end(a, b, c, d); }
92
93 template <class A, class C, class E>
94 A
95 operator()(A a, A b, C c, C d, E e) const
96 { return ::std::find_end(a, b, c, d, e); }
97
98};
99
100// find_first_of ---------------------------------
101
102struct find_first_of {
103
104 template <class Args>
105 struct sig {
106 typedef typename boost::remove_const<
107 typename boost::tuples::element<1, Args>::type
108 >::type type;
109 };
110
111 template <class A, class C>
112 A
113 operator()(A a, A b, C c, C d) const
114 { return ::std::find_first_of(a, b, c, d); }
115
116 template <class A, class C, class E>
117 A
118 operator()(A a, A b, C c, C d, E e) const
119 { return ::std::find_first_of(a, b, c, d, e); }
120
121};
122
123// adjacent_find ---------------------------------
124
125struct adjacent_find {
126
127 template <class Args>
128 struct sig {
129 typedef typename boost::remove_const<
130 typename boost::tuples::element<1, Args>::type
131 >::type type;
132 };
133
134 template <class A>
135 A
136 operator()(A a, A b) const
137 { return ::std::adjacent_find(a, b); }
138
139 template <class A, class C>
140 A
141 operator()(A a, A b, C c) const
142 { return ::std::adjacent_find(a, b, c); }
143
144};
145
146// count ---------------------------------
147
148struct count {
149
150 template <class Args>
151 struct sig {
152 typedef typename ::std::iterator_traits<
153 typename boost::remove_const<
154 typename boost::tuples::element<1, Args>::type
155 >::type
156 >::difference_type type;
157 };
158
159 template <class A, class C >
160 typename ::std::iterator_traits<A>::difference_type
161 operator()(A a, A b, const C& c) const
162 { return ::std::count(a, b, c); }
163};
164
165// count_if ---------------------------------
166
167struct count_if {
168
169 template <class Args>
170 struct sig {
171 typedef typename ::std::iterator_traits<
172 typename boost::remove_const<
173 typename boost::tuples::element<1, Args>::type
174 >::type
175 >::difference_type type;
176 };
177
178 template <class A, class C >
179 typename ::std::iterator_traits<A>::difference_type
180 operator()(A a, A b, C c) const
181 { return ::std::count_if(a, b, c); }
182};
183
184
185// mismatch ---------------------------------
186
187struct mismatch {
188
189 template <class Args>
190 struct sig {
191 typedef typename boost::remove_const<
192 typename boost::tuples::element<1, Args>::type
193 >::type element1_type;
194
195 typedef typename boost::remove_const<
196 typename boost::tuples::element<3, Args>::type
197 >::type element2_type;
198
199 typedef ::std::pair< element1_type, element2_type > type;
200 };
201
202 template <class A, class C >
203 ::std::pair<A,C>
204 operator()(A a, A b, C c) const
205 { return ::std::mismatch(a, b, c); }
206
207 template <class A, class C, class D>
208 ::std::pair<A,C>
209 operator()(A a, A b, C c, D d) const
210 { return ::std::mismatch(a, b, c, d); }
211
212};
213
214// equal ---------------------------------
215
216struct equal {
217
218 template <class Args>
219 struct sig {
220 typedef bool type;
221 };
222
223 template <class A, class C >
224 bool
225 operator()(A a, A b, C c) const
226 { return ::std::equal(a, b, c); }
227
228 template <class A, class C, class D>
229 bool
230 operator()(A a, A b, C c, D d) const
231 { return ::std::equal(a, b, c, d); }
232
233};
234
235// search --------------------------------
236
237struct search {
238
239 template <class Args>
240 struct sig {
241 typedef typename boost::remove_const<
242 typename boost::tuples::element<1, Args>::type
243 >::type type;
244 };
245
246 template <class A, class C>
247 A
248 operator()(A a, A b, C c, C d) const
249 { return std::search(a, b, c, d);}
250
251 template <class A, class C, class E>
252 A
253 operator()(A a, A b, C c, C d, E e) const
254 { return std::search(a, b, c, d, e);}
255
256};
257
258// copy ---------------------------------
259
260struct copy {
261
262 template <class Args>
263 struct sig {
264 typedef typename boost::remove_const<
265 typename boost::tuples::element<3, Args>::type
266 >::type type;
267 };
268
269 template <class A, class C>
270 C
271 operator()(A a, A b, C c) const
272 { return ::std::copy(a, b, c); }
273
274};
275
276// copy_backward ---------------------------------
277
278struct copy_backward {
279
280 template <class Args>
281 struct sig {
282 typedef typename boost::remove_const<
283 typename boost::tuples::element<3, Args>::type
284 >::type type;
285 };
286
287 template <class A, class C>
288 C
289 operator()(A a, A b, C c) const
290 { return ::std::copy_backward(a, b, c); }
291
292};
293
294// swap ---------------------------------
295
296struct swap {
297
298 template <class Args>
299 struct sig {
300 typedef void type;
301 };
302
303 template <class A>
304 void
305 operator()(A a, A b) const
306 { ::std::swap(a, b); }
307
308};
309
310// swap_ranges ---------------------------------
311
312struct swap_ranges {
313
314 template <class Args>
315 struct sig {
316 typedef typename boost::remove_const<
317 typename boost::tuples::element<3, Args>::type
318 >::type type;
319 };
320
321 template <class A, class C>
322 C
323 operator()(A a, A b, C c) const
324 { return ::std::swap_ranges(a, b, c); }
325
326};
327
328// iter_swap ---------------------------------
329
330struct iter_swap {
331
332 template <class Args>
333 struct sig {
334 typedef void type;
335 };
336
337 template <class A>
338 void
339 operator()(A a, A b) const
340 { ::std::iter_swap(a, b); }
341
342};
343
344
345// transform --------------------------------
346
347struct transform {
348
349 template <class Args>
350 struct sig {
351 typedef typename boost::remove_const<
352 typename boost::tuples::element<
353 boost::tuples::length<Args>::value - 2,
354 Args
355 >::type
356 >::type type;
357 };
358
359 template <class A, class C, class D>
360 C
361 operator()(A a, A b, C c, D d) const
362 { return std::transform(a, b, c, d);}
363
364 template <class A, class C, class D, class E>
365 D
366 operator()(A a, A b, C c, D d, E e) const
367 { return std::transform(a, b, c, d, e);}
368
369};
370
371// replace ---------------------------------
372
373struct replace {
374
375 template <class Args>
376 struct sig {
377 typedef void type;
378 };
379
380 template <class A, class C>
381 void
382 operator()(A a, A b, const C& c, const C& d) const
383 { ::std::replace(a, b, c, d); }
384
385};
386
387// replace_if ---------------------------------
388
389struct replace_if {
390
391 template <class Args>
392 struct sig {
393 typedef void type;
394 };
395
396 template <class A, class C, class D>
397 void
398 operator()(A a, A b, C c, const D& d) const
399 { ::std::replace_if(a, b, c, d); }
400
401};
402
403// replace_copy ---------------------------------
404
405struct replace_copy {
406
407 template <class Args>
408 struct sig {
409 typedef typename boost::remove_const<
410 typename boost::tuples::element<3, Args>::type
411 >::type type;
412 };
413
414 template <class A, class C, class D>
415 C
416 operator()(A a, A b, C c, const D& d, const D& e) const
417 { return ::std::replace_copy(a, b, c, d, e); }
418
419};
420
421// replace_copy_if ---------------------------------
422
423struct replace_copy_if {
424
425 template <class Args>
426 struct sig {
427 typedef typename boost::remove_const<
428 typename boost::tuples::element<3, Args>::type
429 >::type type;
430 };
431
432 template <class A, class C, class D, class E>
433 C
434 operator()(A a, A b, C c, D d, const E& e) const
435 { return ::std::replace_copy_if(a, b, c, d, e); }
436
437};
438
439// fill ---------------------------------
440
441struct fill {
442
443 template <class Args>
444 struct sig {
445 typedef void type;
446 };
447
448 template <class A, class C>
449 void
450 operator()(A a, A b, const C& c) const
451 { ::std::fill(a, b, c); }
452
453};
454
455// fill_n ---------------------------------
456
457struct fill_n {
458
459 template <class Args>
460 struct sig {
461 typedef void type;
462 };
463
464 template <class A, class B, class C>
465 void
466 operator()(A a, B b, const C& c) const
467 { ::std::fill_n(a, b, c); }
468
469};
470
471// generate ---------------------------------
472
473struct generate {
474
475 template <class Args>
476 struct sig {
477 typedef void type;
478 };
479
480 template <class A, class C>
481 void
482 operator()(A a, A b, C c) const
483 { ::std::generate(a, b, c); }
484
485};
486
487// generate_n ---------------------------------
488
489struct generate_n {
490
491 template <class Args>
492 struct sig {
493 typedef void type;
494 };
495
496 template <class A, class B, class C>
497 void
498 operator()(A a, B b, C c) const
499 { ::std::generate_n(a, b, c); }
500
501};
502
503// remove ---------------------------------
504
505struct remove {
506
507 template <class Args>
508 struct sig {
509 typedef typename boost::remove_const<
510 typename boost::tuples::element<1, Args>::type
511 >::type type;
512 };
513
514 template <class A, class C >
515 A
516 operator()(A a, A b, const C& c) const
517 { return ::std::remove(a, b, c); }
518};
519
520// remove_if ---------------------------------
521
522struct remove_if {
523
524 template <class Args>
525 struct sig {
526 typedef typename boost::remove_const<
527 typename boost::tuples::element<1, Args>::type
528 >::type type;
529 };
530
531 template <class A, class C >
532 A
533 operator()(A a, A b, C c) const
534 { return ::std::remove_if(a, b, c); }
535};
536
537// remove_copy ---------------------------------
538
539struct remove_copy {
540
541 template <class Args>
542 struct sig {
543 typedef typename boost::remove_const<
544 typename boost::tuples::element<3, Args>::type
545 >::type type;
546 };
547
548 template <class A, class C, class D >
549 C
550 operator()(A a, A b, C c, const D& d) const
551 { return ::std::remove_copy(a, b, c, d); }
552};
553
554// remove_copy_if ---------------------------------
555
556struct remove_copy_if {
557
558 template <class Args>
559 struct sig {
560 typedef typename boost::remove_const<
561 typename boost::tuples::element<3, Args>::type
562 >::type type;
563 };
564
565 template <class A, class C, class D >
566 C
567 operator()(A a, A b, C c, D d) const
568 { return ::std::remove_copy_if(a, b, c, d); }
569};
570
571// unique ---------------------------------
572
573struct unique {
574
575 template <class Args>
576 struct sig {
577 typedef typename boost::remove_const<
578 typename boost::tuples::element<1, Args>::type
579 >::type type;
580 };
581
582 template <class A>
583 A
584 operator()(A a, A b) const
585 { return ::std::unique(a, b); }
586
587 template <class A, class C>
588 A
589 operator()(A a, A b, C c) const
590 { return ::std::unique(a, b, c); }
591
592};
593
594// unique_copy ---------------------------------
595
596struct unique_copy {
597
598 template <class Args>
599 struct sig {
600 typedef typename boost::remove_const<
601 typename boost::tuples::element<3, Args>::type
602 >::type type;
603 };
604
605 template <class A, class C >
606 C
607 operator()(A a, A b, C c) const
608 { return ::std::unique_copy(a, b, c); }
609
610 template <class A, class C, class D>
611 C
612 operator()(A a, A b, C c, D d) const
613 { return ::std::unique_copy(a, b, c, d); }
614
615};
616
617// reverse ---------------------------------
618
619struct reverse {
620
621 template <class Args>
622 struct sig {
623 typedef void type;
624 };
625
626 template <class A>
627 void
628 operator()(A a, A b) const
629 { ::std::reverse(a, b); }
630
631};
632
633// reverse_copy ---------------------------------
634
635struct reverse_copy {
636
637 template <class Args>
638 struct sig {
639 typedef typename boost::remove_const<
640 typename boost::tuples::element<3, Args>::type
641 >::type type;
642 };
643
644 template <class A, class C >
645 C
646 operator()(A a, A b, C c) const
647 { return ::std::reverse_copy(a, b, c); }
648
649};
650
651// rotate ---------------------------------
652
653struct rotate {
654
655 template <class Args>
656 struct sig {
657 typedef void type;
658 };
659
660 template <class A>
661 void
662 operator()(A a, A b, A c) const
663 { ::std::rotate(a, b, c); }
664
665};
666
667// rotate_copy ---------------------------------
668
669struct rotate_copy {
670
671 template <class Args>
672 struct sig {
673 typedef typename boost::remove_const<
674 typename boost::tuples::element<3, Args>::type
675 >::type type;
676 };
677
678 template <class A, class D>
679 D
680 operator()(A a, A b, A c, D d) const
681 { return ::std::rotate_copy(a, b, c, d); }
682
683};
684
685// random_shuffle ---------------------------------
686
687#ifndef BOOST_NO_CXX98_RANDOM_SHUFFLE
688
689struct random_shuffle {
690
691 template <class Args>
692 struct sig {
693 typedef void type;
694 };
695
696 template <class A>
697 void
698 operator()(A a, A b) const
699 { ::std::random_shuffle(a, b); }
700
701 template <class A, class C>
702 void
703 operator()(A a, A b, const C& c) const
704 { ::std::random_shuffle(a, b, c); }
705
706};
707
708#endif
709
710// partition ---------------------------------
711
712struct partition {
713
714 template <class Args>
715 struct sig {
716 typedef typename boost::remove_const<
717 typename boost::tuples::element<1, Args>::type
718 >::type type;
719 };
720
721 template <class A, class C>
722 A
723 operator()(A a, A b, C c) const
724 { return ::std::partition(a, b, c); }
725
726};
727
728// stable_partition ---------------------------------
729
730struct stable_partition {
731
732 template <class Args>
733 struct sig {
734 typedef typename boost::remove_const<
735 typename boost::tuples::element<1, Args>::type
736 >::type type;
737 };
738
739 template <class A, class C>
740 A
741 operator()(A a, A b, C c) const
742 { return ::std::stable_partition(a, b, c); }
743
744};
745
746// sort ---------------------------------
747
748struct sort {
749
750 template <class Args>
751 struct sig {
752 typedef void type;
753 };
754
755 template <class A>
756 void
757 operator()(A a, A b) const
758 { ::std::sort(a, b); }
759
760 template <class A, class C>
761 void
762 operator()(A a, A b, C c) const
763 { ::std::sort(a, b, c); }
764
765};
766
767// stable_sort ---------------------------------
768
769struct stable_sort {
770
771 template <class Args>
772 struct sig {
773 typedef void type;
774 };
775
776 template <class A>
777 void
778 operator()(A a, A b) const
779 { ::std::stable_sort(a, b); }
780
781 template <class A, class C>
782 void
783 operator()(A a, A b, C c) const
784 { ::std::stable_sort(a, b, c); }
785
786};
787
788// partial_sort ---------------------------------
789
790struct partial_sort {
791
792 template <class Args>
793 struct sig {
794 typedef void type;
795 };
796
797 template <class A>
798 void
799 operator()(A a, A b, A c) const
800 { ::std::partial_sort(a, b, c); }
801
802 template <class A, class D>
803 void
804 operator()(A a, A b, A c, D d) const
805 { ::std::partial_sort(a, b, c, d); }
806
807};
808
809// partial_sort_copy ---------------------------------
810
811struct partial_sort_copy {
812
813 template <class Args>
814 struct sig {
815 typedef typename boost::remove_const<
816 typename boost::tuples::element<3, Args>::type
817 >::type type;
818 };
819
820 template <class A, class C>
821 C
822 operator()(A a, A b, C c, C d) const
823 { return ::std::partial_sort_copy(a, b, c, d); }
824
825 template <class A, class C, class E >
826 C
827 operator()(A a, A b, C c, C d, E e) const
828 { return ::std::partial_sort_copy(a, b, c, d, e); }
829};
830
831// nth_element ---------------------------------
832
833struct nth_element {
834
835 template <class Args>
836 struct sig {
837 typedef void type;
838 };
839
840 template <class A>
841 void
842 operator()(A a, A b, A c) const
843 { ::std::nth_element(a, b, c); }
844
845 template <class A, class D>
846 void
847 operator()(A a, A b, A c, D d) const
848 { ::std::nth_element(a, b, c, d); }
849
850};
851
852// lower_bound ---------------------------------
853
854struct lower_bound {
855
856 template <class Args>
857 struct sig {
858 typedef typename boost::remove_const<
859 typename boost::tuples::element<1, Args>::type
860 >::type type;
861 };
862
863 template <class A, class C>
864 A
865 operator()(A a, A b, const C& c) const
866 { return ::std::lower_bound(a, b, c); }
867
868 template <class A, class C, class D>
869 A
870 operator()(A a, A b, const C& c, D d) const
871 { return ::std::lower_bound(a, b, c, d); }
872
873};
874
875// upper_bound ---------------------------------
876
877struct upper_bound {
878
879 template <class Args>
880 struct sig {
881 typedef typename boost::remove_const<
882 typename boost::tuples::element<1, Args>::type
883 >::type type;
884 };
885
886 template <class A, class C>
887 A
888 operator()(A a, A b, const C& c) const
889 { return ::std::upper_bound(a, b, c); }
890
891 template <class A, class C, class D>
892 A
893 operator()(A a, A b, const C& c, D d) const
894 { return ::std::upper_bound(a, b, c, d); }
895
896};
897
898// equal_range ---------------------------------
899
900struct equal_range {
901
902 template <class Args>
903 struct sig {
904 typedef typename boost::remove_const<
905 typename boost::tuples::element<1, Args>::type
906 >::type element_type;
907
908 typedef ::std::pair< element_type, element_type > type;
909 };
910
911 template <class A, class C>
912 ::std::pair<A,A>
913 operator()(A a, A b, const C& c) const
914 { return ::std::equal_range(a, b, c); }
915
916 template <class A, class C, class D>
917 ::std::pair<A,A>
918 operator()(A a, A b, const C& c, D d) const
919 { return ::std::equal_range(a, b, c, d); }
920
921};
922
923// binary_search ---------------------------------
924
925struct binary_search {
926
927 template <class Args>
928 struct sig {
929 typedef bool type;
930 };
931
932 template <class A, class C >
933 bool
934 operator()(A a, A b, const C& c) const
935 { return ::std::binary_search(a, b, c); }
936
937 template <class A, class C, class D>
938 bool
939 operator()(A a, A b, const C& c, D d) const
940 { return ::std::binary_search(a, b, c, d); }
941
942};
943
944// merge --------------------------------
945
946struct merge {
947
948 template <class Args>
949 struct sig {
950 typedef typename boost::remove_const<
951 typename boost::tuples::element<5, Args>::type
952 >::type type;
953 };
954
955 template <class A, class C, class E>
956 E
957 operator()(A a, A b, C c, C d, E e) const
958 { return std::merge(a, b, c, d, e);}
959
960 template <class A, class C, class E, class F>
961 E
962 operator()(A a, A b, C c, C d, E e, F f) const
963 { return std::merge(a, b, c, d, e, f);}
964
965};
966
967// inplace_merge ---------------------------------
968
969struct inplace_merge {
970
971 template <class Args>
972 struct sig {
973 typedef void type;
974 };
975
976 template <class A>
977 void
978 operator()(A a, A b, A c) const
979 { ::std::inplace_merge(a, b, c); }
980
981 template <class A, class D>
982 void
983 operator()(A a, A b, A c, D d) const
984 { ::std::inplace_merge(a, b, c, d); }
985
986};
987
988// includes ---------------------------------
989
990struct includes {
991
992 template <class Args>
993 struct sig {
994 typedef bool type;
995 };
996
997 template <class A, class C>
998 bool
999 operator()(A a, A b, C c, C d) const
1000 { return ::std::includes(a, b, c, d); }
1001
1002 template <class A, class C, class E>
1003 bool
1004 operator()(A a, A b, C c, C d, E e) const
1005 { return ::std::includes(a, b, c, d, e); }
1006
1007};
1008
1009// set_union --------------------------------
1010
1011struct set_union {
1012
1013 template <class Args>
1014 struct sig {
1015 typedef typename boost::remove_const<
1016 typename boost::tuples::element<5, Args>::type
1017 >::type type;
1018 };
1019
1020 template <class A, class C, class E>
1021 E
1022 operator()(A a, A b, C c, C d, E e) const
1023 { return std::set_union(a, b, c, d, e);}
1024
1025 template <class A, class C, class E, class F>
1026 E
1027 operator()(A a, A b, C c, C d, E e, F f) const
1028 { return std::set_union(a, b, c, d, e, f);}
1029
1030};
1031
1032// set_intersection --------------------------------
1033
1034struct set_intersection {
1035
1036 template <class Args>
1037 struct sig {
1038 typedef typename boost::remove_const<
1039 typename boost::tuples::element<5, Args>::type
1040 >::type type;
1041 };
1042
1043 template <class A, class C, class E>
1044 E
1045 operator()(A a, A b, C c, C d, E e) const
1046 { return std::set_intersection(a, b, c, d, e);}
1047
1048 template <class A, class C, class E, class F>
1049 E
1050 operator()(A a, A b, C c, C d, E e, F f) const
1051 { return std::set_intersection(a, b, c, d, e, f);}
1052
1053};
1054
1055// set_difference --------------------------------
1056
1057struct set_difference {
1058
1059 template <class Args>
1060 struct sig {
1061 typedef typename boost::remove_const<
1062 typename boost::tuples::element<5, Args>::type
1063 >::type type;
1064 };
1065
1066 template <class A, class C, class E>
1067 E
1068 operator()(A a, A b, C c, C d, E e) const
1069 { return std::set_difference(a, b, c, d, e);}
1070
1071 template <class A, class C, class E, class F>
1072 E
1073 operator()(A a, A b, C c, C d, E e, F f) const
1074 { return std::set_difference(a, b, c, d, e, f);}
1075
1076};
1077
1078
1079// set_symmetric_difference --------------------------------
1080
1081struct set_symmetric_difference {
1082
1083 template <class Args>
1084 struct sig {
1085 typedef typename boost::remove_const<
1086 typename boost::tuples::element<5, Args>::type
1087 >::type type;
1088 };
1089
1090 template <class A, class C, class E>
1091 E
1092 operator()(A a, A b, C c, C d, E e) const
1093 { return std::set_symmetric_difference(a, b, c, d, e);}
1094
1095 template <class A, class C, class E, class F>
1096 E
1097 operator()(A a, A b, C c, C d, E e, F f) const
1098 { return std::set_symmetric_difference(a, b, c, d, e, f);}
1099
1100};
1101
1102// push_heap ---------------------------------
1103
1104struct push_heap {
1105
1106 template <class Args>
1107 struct sig {
1108 typedef void type;
1109 };
1110
1111 template <class A>
1112 void
1113 operator()(A a, A b) const
1114 { ::std::push_heap(a, b); }
1115
1116 template <class A, class C>
1117 void
1118 operator()(A a, A b, C c) const
1119 { ::std::push_heap(a, b, c); }
1120
1121};
1122
1123// pop_heap ---------------------------------
1124
1125struct pop_heap {
1126
1127 template <class Args>
1128 struct sig {
1129 typedef void type;
1130 };
1131
1132 template <class A>
1133 void
1134 operator()(A a, A b) const
1135 { ::std::pop_heap(a, b); }
1136
1137 template <class A, class C>
1138 void
1139 operator()(A a, A b, C c) const
1140 { ::std::pop_heap(a, b, c); }
1141
1142};
1143
1144
1145// make_heap ---------------------------------
1146
1147struct make_heap {
1148
1149 template <class Args>
1150 struct sig {
1151 typedef void type;
1152 };
1153
1154 template <class A>
1155 void
1156 operator()(A a, A b) const
1157 { ::std::make_heap(a, b); }
1158
1159 template <class A, class C>
1160 void
1161 operator()(A a, A b, C c) const
1162 { ::std::make_heap(a, b, c); }
1163
1164};
1165
1166// sort_heap ---------------------------------
1167
1168struct sort_heap {
1169
1170 template <class Args>
1171 struct sig {
1172 typedef void type;
1173 };
1174
1175 template <class A>
1176 void
1177 operator()(A a, A b) const
1178 { ::std::sort_heap(a, b); }
1179
1180 template <class A, class C>
1181 void
1182 operator()(A a, A b, C c) const
1183 { ::std::sort_heap(a, b, c); }
1184
1185};
1186
1187// min ---------------------------------
1188
1189struct min {
1190
1191 template <class Args>
1192 struct sig {
1193 typedef typename boost::remove_const<
1194 typename boost::tuples::element<1, Args>::type
1195 >::type type;
1196 };
1197
1198 template <class A>
1199 A
1200 operator()(const A& a, const A& b) const
1201 { return (::std::min)(a, b); }
1202
1203 template <class A, class C>
1204 A
1205 operator()(const A& a, const A& b, C c) const
1206 { return (::std::min)(a, b, c); }
1207
1208};
1209
1210// max ---------------------------------
1211
1212struct max {
1213
1214 template <class Args>
1215 struct sig {
1216 typedef typename boost::remove_const<
1217 typename boost::tuples::element<1, Args>::type
1218 >::type type;
1219 };
1220
1221 template <class A>
1222 A
1223 operator()(const A& a, const A& b) const
1224 { return (::std::max)(a, b); }
1225
1226 template <class A, class C>
1227 A
1228 operator()(const A& a, const A& b, C c) const
1229 { return (::std::max)(a, b, c); }
1230
1231};
1232
1233struct min_element {
1234
1235 template <class Args>
1236 struct sig {
1237 typedef typename boost::remove_const<
1238 typename boost::tuples::element<1, Args>::type
1239 >::type type;
1240 };
1241
1242 template <class A>
1243 A
1244 operator()(A a, A b) const
1245 { return ::std::min_element(a, b); }
1246
1247 template <class A, class C>
1248 A
1249 operator()(A a, A b, C c) const
1250 { return ::std::min_element(a, b, c); }
1251
1252};
1253
1254// max_element ---------------------------------
1255
1256struct max_element {
1257
1258 template <class Args>
1259 struct sig {
1260 typedef typename boost::remove_const<
1261 typename boost::tuples::element<1, Args>::type
1262 >::type type;
1263 };
1264
1265 template <class A>
1266 A
1267 operator()(A a, A b) const
1268 { return ::std::max_element(a, b); }
1269
1270 template <class A, class C>
1271 A
1272 operator()(A a, A b, C c) const
1273 { return ::std::max_element(a, b, c); }
1274
1275};
1276
1277
1278// lexicographical_compare ---------------------------------
1279
1280struct lexicographical_compare {
1281
1282 template <class Args>
1283 struct sig {
1284 typedef bool type;
1285 };
1286
1287 template <class A, class C>
1288 bool
1289 operator()(A a, A b, C c, C d) const
1290 { return ::std::lexicographical_compare(a, b, c, d); }
1291
1292 template <class A, class C, class E>
1293 bool
1294 operator()(A a, A b, C c, C d, E e) const
1295 { return ::std::lexicographical_compare(a, b, c, d, e); }
1296
1297};
1298
1299// next_permutation ---------------------------------
1300
1301struct next_permutation {
1302
1303 template <class Args>
1304 struct sig {
1305 typedef bool type;
1306 };
1307
1308 template <class A>
1309 bool
1310 operator()(A a, A b) const
1311 { return ::std::next_permutation(a, b); }
1312
1313 template <class A, class C >
1314 bool
1315 operator()(A a, A b, C c) const
1316 { return ::std::next_permutation(a, b, c); }
1317
1318};
1319
1320// prev_permutation ---------------------------------
1321
1322struct prev_permutation {
1323
1324 template <class Args>
1325 struct sig {
1326 typedef bool type;
1327 };
1328
1329 template <class A>
1330 bool
1331 operator()(A a, A b) const
1332 { return ::std::prev_permutation(a, b); }
1333
1334 template <class A, class C >
1335 bool
1336 operator()(A a, A b, C c) const
1337 { return ::std::prev_permutation(a, b, c); }
1338
1339};
1340
1341
1342
1343
1344
1345} // end of ll namespace
1346
1347// There is no good way to call an overloaded member function in a
1348// lambda expression.
1349// The macro below defines a function object class for calling a
1350// const_iterator returning member function of a container.
1351
1352#define CALL_MEMBER(X) \
1353struct call_##X { \
1354template <class Args> \
1355 struct sig { \
1356 typedef typename boost::remove_const< \
1357 typename boost::tuples::element<1, Args>::type \
1358 >::type::const_iterator type; \
1359 }; \
1360 \
1361 template<class T> \
1362 typename T::const_iterator \
1363 operator()(const T& t) const \
1364 { \
1365 return t.X(); \
1366 } \
1367};
1368
1369// create call_begin and call_end classes
1370CALL_MEMBER(begin)
1371CALL_MEMBER(end)
1372
1373#undef CALL_MEMBER
1374
1375} // end of lambda namespace
1376} // end of boost namespace
1377
1378
1379
1380#endif
1381

source code of boost/libs/lambda/include/boost/lambda/algorithm.hpp