Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ahFunction.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
45// Functor implementations -*- C++ -*-
46
47/*
48 *
49 * Copyright (c) 1994
50 * Hewlett-Packard Company
51 *
52 * Permission to use, copy, modify, distribute and sell this software
53 * and its documentation for any purpose is hereby granted without fee,
54 * provided that the above copyright notice appear in all copies and
55 * that both that copyright notice and this permission notice appear
56 * in supporting documentation. Hewlett-Packard Company makes no
57 * representations about the suitability of this software for any
58 * purpose. It is provided "as is" without express or implied warranty.
59 *
60 *
61 * Copyright (c) 1996-1998
62 * Silicon Graphics Computer Systems, Inc.
63 *
64 * Permission to use, copy, modify, distribute and sell this software
65 * and its documentation for any purpose is hereby granted without fee,
66 * provided that the above copyright notice appear in all copies and
67 * that both that copyright notice and this permission notice appear
68 * in supporting documentation. Silicon Graphics makes no
69 * representations about the suitability of this software for any
70 * purpose. It is provided "as is" without express or implied warranty.
71 */
72
73# ifndef AHFUNCTION_H
74# define AHFUNCTION_H
75
76# include <utility>
77
78namespace Aleph
79{
80
81 template <class _Arg, class _Result>
83 {
84 typedef _Arg argument_type;
85 typedef _Result result_type;
86 };
87
88 template <class _Arg1, class _Arg2, class _Result>
90 {
91 typedef _Arg1 first_argument_type; // the type of the first argument
92 typedef _Arg2 second_argument_type; // the type of the second argument
93 typedef _Result result_type; // type of the return type
94 };
95
96
97 namespace function_detail
98 {
105 template <class T>
106 concept nothrow_less_than = requires (const T & x, const T & y)
107 {
108 { static_cast<bool>(x < y) } noexcept;
109 };
110
111 // The same for the operators of the other functors below; those that
112 // give a _Tp count its construction from the result too, and those
113 // that give a bool, the conversion of the result to it
114
116 template <class T>
117 concept nothrow_plus = requires (const T & x, const T & y)
118 {
119 { T(x + y) } noexcept;
120 };
121
123 template <class T>
124 concept nothrow_minus = requires (const T & x, const T & y)
125 {
126 { T(x - y) } noexcept;
127 };
128
130 template <class T>
131 concept nothrow_multiplies = requires (const T & x, const T & y)
132 {
133 { T(x * y) } noexcept;
134 };
135
137 template <class T>
138 concept nothrow_divides = requires (const T & x, const T & y)
139 {
140 { T(x / y) } noexcept;
141 };
142
144 template <class T>
145 concept nothrow_modulus = requires (const T & x, const T & y)
146 {
147 { T(x % y) } noexcept;
148 };
149
151 template <class T>
152 concept nothrow_negate = requires (const T & x)
153 {
154 { T(-x) } noexcept;
155 };
156
158 template <class T>
159 concept nothrow_equal_to = requires (const T & x, const T & y)
160 {
161 { static_cast<bool>(x == y) } noexcept;
162 };
163
165 template <class T>
166 concept nothrow_not_equal_to = requires (const T & x, const T & y)
167 {
168 { static_cast<bool>(x != y) } noexcept;
169 };
170
172 template <class T>
173 concept nothrow_greater = requires (const T & x, const T & y)
174 {
175 { static_cast<bool>(x > y) } noexcept;
176 };
177
179 template <class T>
180 concept nothrow_greater_equal = requires (const T & x, const T & y)
181 {
182 { static_cast<bool>(x >= y) } noexcept;
183 };
184
186 template <class T>
187 concept nothrow_less_equal = requires (const T & x, const T & y)
188 {
189 { static_cast<bool>(x <= y) } noexcept;
190 };
191
193 template <class T>
194 concept nothrow_logical_and = requires (const T & x, const T & y)
195 {
196 { static_cast<bool>(x and y) } noexcept;
197 };
198
200 template <class T>
201 concept nothrow_logical_or = requires (const T & x, const T & y)
202 {
203 { static_cast<bool>(x or y) } noexcept;
204 };
205
207 template <class T>
208 concept nothrow_logical_not = requires (const T & x)
209 {
210 { static_cast<bool>(not x) } noexcept;
211 };
212 }
213
214
215 template <class _Tp>
216 struct plus : public binary_function<_Tp, _Tp, _Tp>
217 {
218 _Tp operator () (const _Tp& __x, const _Tp& __y) const
220 {
221 return __x + __y;
222 }
223 };
224
225
226 template <class _Tp>
227 struct minus : public binary_function<_Tp, _Tp, _Tp>
228 {
229 _Tp operator () (const _Tp& __x, const _Tp& __y) const
231 {
232 return __x - __y;
233 }
234 };
235
236
237 template <class _Tp>
238 struct multiplies : public binary_function<_Tp, _Tp, _Tp>
239 {
240 _Tp operator () (const _Tp& __x, const _Tp& __y) const
242 {
243 return __x * __y;
244 }
245 };
246
247
248 template <class _Tp>
249 struct divides : public binary_function<_Tp, _Tp, _Tp>
250 {
251 _Tp operator () (const _Tp& __x, const _Tp& __y) const
253 {
254 return __x / __y;
255 }
256 };
257
258
259 template <class _Tp>
260 struct modulus : public binary_function<_Tp, _Tp, _Tp>
261 {
262 _Tp operator () (const _Tp& __x, const _Tp& __y) const
264 {
265 return __x % __y;
266 }
267 };
268
269
270 template <class _Tp>
271 struct negate : public unary_function<_Tp, _Tp>
272 {
273 _Tp operator () (const _Tp& __x) const
275 {
276 return -__x;
277 }
278 };
279
280
281 template <class _Tp>
282 struct equal_to : public binary_function<_Tp, _Tp, bool>
283 {
284 bool operator () (const _Tp& __x, const _Tp& __y) const
286 {
287 return static_cast<bool>(__x == __y);
288 }
289 };
290
291
292 template <class _Tp>
293 struct not_equal_to : public binary_function<_Tp, _Tp, bool>
294 {
295 bool operator()(const _Tp& __x, const _Tp& __y) const
297 {
298 return static_cast<bool>(__x != __y);
299 }
300 };
301
302
303 template <class _Tp>
304 struct greater : public binary_function<_Tp, _Tp, bool>
305 {
306 bool operator () (const _Tp& __x, const _Tp& __y) const
308 {
309 return static_cast<bool>(__x > __y);
310 }
311 };
312
313
314 template <class _Tp>
315 struct less : public binary_function<_Tp, _Tp, bool>
316 {
317 // noexcept as the < of _Tp, so that what it throws reaches the caller
318 // of the heaps, sorts and sets that compare with less
319 bool operator () (const _Tp& __x, const _Tp& __y) const
321 {
322 return static_cast<bool>(__x < __y);
323 }
324 };
325
326
327 template <class _Tp>
328 struct greater_equal : public binary_function<_Tp, _Tp, bool>
329 {
330 bool operator () (const _Tp& __x, const _Tp& __y) const
332 {
333 return static_cast<bool>(__x >= __y);
334 }
335 };
336
337
338 template <class _Tp>
339 struct less_equal : public binary_function<_Tp, _Tp, bool>
340 {
341 bool operator () (const _Tp& __x, const _Tp& __y) const
343 {
344 return static_cast<bool>(__x <= __y);
345 }
346 };
347
348
349 template <class _Tp>
350 struct logical_and : public binary_function<_Tp, _Tp, bool>
351 {
352 bool operator () (const _Tp& __x, const _Tp& __y) const
354 {
355 return static_cast<bool>(__x and __y);
356 }
357 };
358
359
360 template <class _Tp>
361 struct logical_or : public binary_function<_Tp, _Tp, bool>
362 {
363 bool operator () (const _Tp& __x, const _Tp& __y) const
365 {
366 return static_cast<bool>(__x or __y);
367 }
368 };
369
370
371 template <class _Tp>
372 struct logical_not : public unary_function<_Tp, bool>
373 {
374 bool operator () (const _Tp& __x) const
376 {
377 return static_cast<bool>(not __x);
378 }
379 };
380
381
382 template <class _Predicate>
384 : public unary_function <typename _Predicate::argument_type, bool>
385 {
386 protected:
387
388 _Predicate _M_pred;
389
390 public:
391
392 explicit unary_negate (const _Predicate& __x) : _M_pred(__x) {}
393
402 bool operator () (const typename _Predicate::argument_type& __x)
403 const noexcept(noexcept(not static_cast<bool>(_M_pred(__x))))
404 {
405 return not static_cast<bool>(_M_pred(__x));
406 }
407 };
408
409
410 template <class _Predicate> inline
411 unary_negate<_Predicate> not1 (const _Predicate& __pred)
412 {
413 return unary_negate<_Predicate>(__pred);
414 }
415
416
417 template <class _Predicate>
419 : public binary_function<typename _Predicate::first_argument_type,
420 typename _Predicate::second_argument_type,
421 bool>
422 {
423 protected:
424
425 _Predicate _M_pred;
426
427 public:
428
429 explicit binary_negate (const _Predicate& __x) : _M_pred(__x) { }
430
431 bool
432 operator () (const typename _Predicate::first_argument_type& __x,
433 const typename _Predicate::second_argument_type& __y) const
434 {
435 return not _M_pred(__x, __y);
436 }
437 };
438
439
440 template <class _Predicate> inline
441 binary_negate<_Predicate> not2 (const _Predicate& __pred)
442 {
443 return binary_negate<_Predicate>(__pred);
444 }
445
446
447 template <class _Operation>
449 : public unary_function<typename _Operation::second_argument_type,
450 typename _Operation::result_type>
451 {
452 protected:
453
454 _Operation op;
455
456 typename _Operation::first_argument_type value;
457
458 public:
459
460 binder1st(const _Operation& __x,
461 const typename _Operation::first_argument_type& __y)
462 : op(__x), value(__y) {}
463
464 typename _Operation::result_type
465 operator () (const typename _Operation::second_argument_type& __x) const
466 {
467 return op (value, __x);
468 }
469
470 typename _Operation::result_type
471 operator () (typename _Operation::second_argument_type& __x) const
472 {
473 return op(value, __x);
474 }
475 };
476
477
478 template <class _Operation, class _Tp> inline
479 binder1st<_Operation> bind1st(const _Operation& __fn, const _Tp& __x)
480 {
481 typedef typename _Operation::first_argument_type _Arg1_type;
482
483 return binder1st<_Operation> (__fn, _Arg1_type(__x));
484 }
485
486 template <class _Operation>
488 : public unary_function<typename _Operation::first_argument_type,
489 typename _Operation::result_type>
490 {
491 protected:
492
493 _Operation op;
494
495 typename _Operation::second_argument_type value;
496
497 public:
498
499 binder2nd(const _Operation& __x,
500 const typename _Operation::second_argument_type& __y)
501 : op(__x), value (__y) {}
502
503 typename _Operation::result_type
504 operator () (const typename _Operation::first_argument_type& __x) const
505 {
506 return op (__x, value);
507 }
508
509 typename _Operation::result_type
510 operator () (typename _Operation::first_argument_type& __x) const
511 {
512 return op (__x, value);
513 }
514 };
515
516
517 template <class _Operation, class _Tp> inline
518 binder2nd<_Operation> bind2nd (const _Operation& __fn, const _Tp& __x)
519 {
520 typedef typename _Operation::second_argument_type _Arg2_type;
521
522 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
523 }
524
525
526 template <class _Arg, class _Result>
527 class pointer_to_unary_function : public unary_function<_Arg, _Result>
528 {
529 protected:
530
531 _Result (*_M_ptr) (_Arg);
532
533 public:
534
536
537 explicit pointer_to_unary_function(_Result (*__x) (_Arg))
538 : _M_ptr (__x) {}
539
540 _Result operator () (_Arg __x) const
541 {
542 return _M_ptr (__x);
543 }
544 };
545
546
547 template <class _Arg, class _Result> inline
552
553
554 template <class _Arg1, class _Arg2, class _Result>
556 : public binary_function<_Arg1, _Arg2, _Result>
557 {
558 protected:
559
560 _Result (*_M_ptr) (_Arg1, _Arg2);
561
562 public:
563
565
566 explicit pointer_to_binary_function(_Result (*__x) (_Arg1, _Arg2))
567 : _M_ptr(__x) {}
568
569 _Result operator () (_Arg1 __x, _Arg2 __y) const
570 {
571 return _M_ptr(__x, __y);
572 }
573 };
574
575
576 template <class _Arg1, class _Arg2, class _Result> inline
577 pointer_to_binary_function<_Arg1, _Arg2, _Result>
578 ptr_fun (_Result (*__x) (_Arg1, _Arg2) )
579 {
581 }
582
583 template <class _Tp>
584 struct _Identity : public unary_function<_Tp,_Tp>
585 {
586 _Tp & operator () (_Tp& __x) const
587 {
588 return __x;
589 }
590
591 const _Tp& operator () (const _Tp& __x) const
592 {
593 return __x;
594 }
595 };
596
597 template <class _Pair>
598 struct _Select1st : public unary_function<_Pair, typename _Pair::first_type>
599 {
600 typename _Pair::first_type& operator () (_Pair& __x) const
601 {
602 return __x.first;
603 }
604
605 const typename _Pair::first_type& operator () (const _Pair& __x) const
606 {
607 return __x.first;
608 }
609 };
610
611 template <class _Pair>
612 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
613 {
614 typename _Pair::second_type& operator () (_Pair& __x) const
615 {
616 return __x.second;
617 }
618
619 const typename _Pair::second_type& operator () (const _Pair& __x) const
620 {
621 return __x.second;
622 }
623 };
624
625
626 template <class _Ret, class _Tp>
627 class mem_fun_t : public unary_function<_Tp*, _Ret>
628 {
629 public:
630
631 explicit mem_fun_t (_Ret (_Tp::*__pf) () )
632 : _M_f(__pf) {}
633
634 _Ret operator ()(_Tp* __p) const
635 {
636 return (__p->*_M_f)();
637 }
638
639 private:
640
641 _Ret (_Tp::*_M_f) ();
642 };
643
644
645 template <class _Ret, class _Tp>
646 class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
647 {
648 public:
649
650 explicit const_mem_fun_t (_Ret (_Tp::*__pf) () const)
651 : _M_f (__pf) {}
652
653 _Ret operator () (const _Tp* __p) const
654 {
655 return (__p->*_M_f) ();
656 }
657
658 private:
659
660 _Ret (_Tp::*_M_f) () const;
661 };
662
663
664 template <class _Ret, class _Tp>
665 class mem_fun_ref_t : public unary_function<_Tp, _Ret>
666 {
667 public:
668
669 explicit mem_fun_ref_t (_Ret (_Tp::*__pf)())
670 : _M_f (__pf) {}
671
672 _Ret operator () (_Tp& __r) const
673 {
674 return (__r.*_M_f)();
675 }
676
677 private:
678
679 _Ret (_Tp::*_M_f) ();
680 };
681
682
683 template <class _Ret, class _Tp>
684 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
685 {
686 public:
687
688 explicit const_mem_fun_ref_t (_Ret (_Tp::*__pf)() const)
689 : _M_f (__pf) {}
690
691 _Ret operator () (const _Tp& __r) const
692 {
693 return (__r.*_M_f)();
694 }
695
696 private:
697
698 _Ret (_Tp::*_M_f) () const;
699 };
700
701
702 template <class _Ret, class _Tp, class _Arg>
703 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
704 {
705 public:
706
707 explicit mem_fun1_t (_Ret (_Tp::*__pf) (_Arg))
708 : _M_f(__pf) {}
709
710 _Ret operator () (_Tp* __p, _Arg __x) const
711 {
712 return (__p->*_M_f) (__x);
713 }
714
715 private:
716
717 _Ret (_Tp::*_M_f) (_Arg);
718 };
719
720
721 template <class _Ret, class _Tp, class _Arg>
722 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
723 {
724 public:
725
726 explicit const_mem_fun1_t (_Ret (_Tp::*__pf) (_Arg) const)
727 : _M_f (__pf) {}
728
729 _Ret operator () (const _Tp* __p, _Arg __x) const
730 {
731 return (__p->*_M_f)(__x);
732 }
733
734 private:
735
736 _Ret (_Tp::*_M_f) (_Arg) const;
737 };
738
739
740 template <class _Ret, class _Tp, class _Arg>
741 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
742 {
743 public:
744
745 explicit mem_fun1_ref_t (_Ret (_Tp::*__pf) (_Arg))
746 : _M_f (__pf) {}
747
748 _Ret operator () (_Tp& __r, _Arg __x) const
749 {
750 return (__r.*_M_f)(__x);
751 }
752
753 private:
754
755 _Ret (_Tp::*_M_f) (_Arg);
756 };
757
758
759 template <class _Ret, class _Tp, class _Arg>
760 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
761 {
762 public:
763
764 explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
765 : _M_f(__pf) {}
766
767 _Ret operator () (const _Tp& __r, _Arg __x) const
768 {
769 return (__r.*_M_f)(__x);
770 }
771
772 private:
773
774 _Ret (_Tp::*_M_f) (_Arg) const;
775 };
776
777
778 template <class _Tp>
779 class mem_fun_t<void, _Tp> : public unary_function<_Tp*, void>
780 {
781 public:
782
783 explicit mem_fun_t (void (_Tp::*__pf)())
784 : _M_f (__pf) {}
785
786 void operator () (_Tp* __p) const
787 {
788 (__p->*_M_f)();
789 }
790
791 private:
792
793 void (_Tp::*_M_f)();
794 };
795
796
797 template <class _Tp>
798 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*, void>
799 {
800 public:
801
802 explicit const_mem_fun_t (void (_Tp::*__pf)() const)
803 : _M_f (__pf) {}
804
805 void operator () (const _Tp* __p) const
806 {
807 (__p->*_M_f)();
808 }
809
810 private:
811
812 void (_Tp::*_M_f)() const;
813 };
814
815
816 template <class _Tp>
817 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
818 {
819 public:
820
821 explicit mem_fun_ref_t (void (_Tp::*__pf)()) : _M_f (__pf) {}
822
823 void operator () (_Tp& __r) const
824 {
825 (__r.*_M_f)();
826 }
827
828 private:
829
830 void (_Tp::*_M_f)();
831 };
832
833
834 template <class _Tp>
835 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
836 {
837 public:
838
839 explicit const_mem_fun_ref_t (void (_Tp::*__pf) () const)
840 : _M_f (__pf) {}
841
842 void operator () (const _Tp& __r) const
843 {
844 (__r.*_M_f) ();
845 }
846
847 private:
848
849 void (_Tp::*_M_f) () const;
850 };
851
852
853 template <class _Tp, class _Arg>
854 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*, _Arg, void>
855 {
856 public:
857
858 explicit mem_fun1_t(void (_Tp::*__pf) (_Arg)) : _M_f (__pf) {}
859
860 void operator () (_Tp* __p, _Arg __x) const
861 {
862 (__p->*_M_f)(__x);
863 }
864
865 private:
866
867 void (_Tp::*_M_f) (_Arg);
868 };
869
870
871 template <class _Tp, class _Arg>
872 class const_mem_fun1_t<void, _Tp, _Arg>
873 : public binary_function<const _Tp*, _Arg, void>
874 {
875 public:
876
877 explicit const_mem_fun1_t (void (_Tp::*__pf) (_Arg) const) : _M_f (__pf) {}
878
879 void operator () (const _Tp* __p, _Arg __x) const
880 {
881 (__p->*_M_f)(__x);
882 }
883
884 private:
885
886 void (_Tp::*_M_f)(_Arg) const;
887 };
888
889
890 template <class _Tp, class _Arg>
891 class mem_fun1_ref_t<void, _Tp, _Arg>
892 : public binary_function<_Tp, _Arg, void>
893 {
894 public:
895
896 explicit mem_fun1_ref_t (void (_Tp::*__pf) (_Arg)) : _M_f (__pf) {}
897
898 void operator () (_Tp& __r, _Arg __x) const
899 {
900 (__r.*_M_f)(__x);
901 }
902
903 private:
904
905 void (_Tp::*_M_f) (_Arg);
906 };
907
908
909 template <class _Tp, class _Arg>
910 class const_mem_fun1_ref_t<void, _Tp, _Arg>
911 : public binary_function<_Tp, _Arg, void>
912 {
913 public:
914
915 explicit const_mem_fun1_ref_t (void (_Tp::*__pf) (_Arg) const)
916 : _M_f (__pf) {}
917
918 void operator () (const _Tp& __r, _Arg __x) const
919 {
920 (__r.*_M_f) (__x);
921 }
922
923 private:
924
925 void (_Tp::*_M_f)(_Arg) const;
926 };
927
928
929 template <class _Ret, class _Tp> inline
930 mem_fun_t<_Ret, _Tp> mem_fun (_Ret (_Tp::*__f) () )
931 {
932 return mem_fun_t<_Ret, _Tp> (__f);
933 }
934
935 template <class _Ret, class _Tp> inline
936 const_mem_fun_t<_Ret, _Tp> mem_fun (_Ret (_Tp::*__f) () const)
937 {
938 return const_mem_fun_t<_Ret, _Tp> (__f);
939 }
940
941 template <class _Ret, class _Tp> inline
943 {
944 return mem_fun_ref_t<_Ret, _Tp> (__f);
945 }
946
947 template <class _Ret, class _Tp> inline
948 const_mem_fun_ref_t<_Ret, _Tp> mem_fun_ref (_Ret (_Tp::*__f) () const)
949 {
950 return const_mem_fun_ref_t<_Ret, _Tp> (__f);
951 }
952
953 template <class _Ret, class _Tp, class _Arg> inline
954 mem_fun1_t<_Ret, _Tp, _Arg> mem_fun (_Ret (_Tp::*__f) (_Arg))
955 {
956 return mem_fun1_t<_Ret, _Tp, _Arg> (__f);
957 }
958
959 template <class _Ret, class _Tp, class _Arg> inline
960 const_mem_fun1_t<_Ret, _Tp, _Arg> mem_fun (_Ret (_Tp::*__f) (_Arg) const)
961 {
963 }
964
965 template <class _Ret, class _Tp, class _Arg> inline
967 {
969 }
970
971 template <class _Ret, class _Tp, class _Arg> inline
972 const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
973 mem_fun_ref (_Ret (_Tp::*__f) (_Arg) const)
974 {
976 }
977
978
990 template <class T, class Compare> inline
991bool less_than(const T & op1, const T & op2, Compare & cmp)
992{
993 return cmp (op1, op2);
994}
995
996
1001 template <class T, class Compare> inline
1002bool less_than(const T & op1, const T & op2, Compare && cmp = Compare())
1003{
1004 return less_than <T, Compare> (op1, op2, cmp);
1005}
1006
1007
1019 template <class T, class Compare> inline
1020bool less_or_equal_than(const T& op1, const T& op2, Compare & cmp)
1021{
1022 if (cmp(op1, op2))
1023 return true;
1024
1025 if (cmp(op2, op1))
1026 return false;
1027
1028 return true;
1029}
1030
1031
1036 template <class T, class Compare> inline
1037bool less_or_equal_than(const T& op1, const T& op2, Compare && cmp = Compare())
1038{
1039 return less_or_equal_than<T, Compare>(op1, op2, cmp);
1040}
1041
1042
1051 template <class T, class Compare> inline
1052bool greater_than(const T& op1, const T& op2, Compare && cmp = Compare())
1053{
1054 return not less_or_equal_than<T, Compare>(op1, op2,
1055 std::forward<Compare>(cmp));
1056}
1057
1062 template <class T, class Compare> inline
1063bool greater_than(const T& op1, const T& op2, Compare & cmp)
1064{
1065 return not less_or_equal_than<T, Compare> (op1, op2, cmp);
1066}
1067
1076 template <class T, class Compare> inline
1077bool greater_or_equal_than(const T& op1, const T & op2,
1078 Compare && cmp = Compare())
1079{
1080 return not less_than<T, Compare> (op1, op2, std::forward<Compare>(cmp));
1081}
1082
1087 template <class T, class Compare> inline
1088bool greater_or_equal_than(const T& op1, const T& op2, Compare & cmp)
1089{
1090 return not less_than<T, Compare> (op1, op2, cmp);
1091}
1092
1101 template <class T, class Compare> inline
1102bool no_equals(const T & op1, const T & op2, Compare && cmp = Compare())
1103{
1104 return static_cast<bool>(cmp(op1, op2)) or static_cast<bool>(cmp(op2, op1));
1105}
1106
1111 template <class T, class Compare> inline
1112bool no_equals(const T & op1, const T & op2, Compare & cmp)
1113{
1114 return static_cast<bool>(cmp(op1, op2)) or static_cast<bool>(cmp(op2, op1));
1115}
1116
1125 template <class T, class Compare> inline
1126bool are_equals(const T & op1, const T & op2, Compare && cmp = Compare())
1127{
1128 return not no_equals <T, Compare> (op1, op2, std::forward<Compare>(cmp));
1129}
1130
1135 template <class T, class Compare> inline
1136bool are_equals(const T & op1, const T & op2, Compare & cmp)
1137{
1138 return not no_equals <T, Compare> (op1, op2, cmp);
1139}
1140
1151 template <class T, class Compare>
1153{
1154 const Compare & cmp;
1155
1156public:
1157
1163 constexpr Inversed_Compare(const Compare & __cmp) noexcept : cmp(__cmp) { /* empty */ }
1164
1165 Inversed_Compare(Compare && cmp = Compare()) noexcept
1167 { /* empty */ }
1168
1169 // noexcept as the comparison: heapsort() and the heapsort to which
1170 // introsort() falls back compare through it, and a comparator that threw
1171 // ended the program where introsort() promises to let it through
1172 constexpr bool operator () (const T & op1, const T & op2) const
1173 noexcept(noexcept(static_cast<bool>(cmp(op2, op1))))
1174 {
1175 return static_cast<bool>(cmp(op2, op1));
1176 }
1177};
1178
1183 template <class T, class Compare>
1185{
1186 bool operator () (const T & op1, const T & op2) const
1187 {
1188 if (Compare () (op1, op2))
1189 return true;
1190
1191 if (Compare () (op2, op1))
1192 return false;
1193
1194 return true;
1195 }
1196};
1197
1198} // namespace Aleph
1199
1200#endif /* AHFUNCTION_H */
1201
1202
Performs order reversal of Compare by swapping operands.
const Compare & cmp
constexpr Inversed_Compare(const Compare &__cmp) noexcept
The inversion of __cmp, which is not copied.
Inversed_Compare(Compare &&cmp=Compare()) noexcept
constexpr bool operator()(const T &op1, const T &op2) const noexcept(noexcept(static_cast< bool >(cmp(op2, op1))))
bool operator()(const typename _Predicate::first_argument_type &__x, const typename _Predicate::second_argument_type &__y) const
Definition ahFunction.H:432
binary_negate(const _Predicate &__x)
Definition ahFunction.H:429
binder1st(const _Operation &__x, const typename _Operation::first_argument_type &__y)
Definition ahFunction.H:460
_Operation::first_argument_type value
Definition ahFunction.H:456
_Operation::result_type operator()(const typename _Operation::second_argument_type &__x) const
Definition ahFunction.H:465
_Operation op
Definition ahFunction.H:454
_Operation::second_argument_type value
Definition ahFunction.H:495
_Operation::result_type operator()(const typename _Operation::first_argument_type &__x) const
Definition ahFunction.H:504
binder2nd(const _Operation &__x, const typename _Operation::second_argument_type &__y)
Definition ahFunction.H:499
_Operation op
Definition ahFunction.H:493
const_mem_fun1_ref_t(void(_Tp::*__pf)(_Arg) const)
Definition ahFunction.H:915
_Ret(_Tp::* _M_f)(_Arg) const
Definition ahFunction.H:774
const_mem_fun1_ref_t(_Ret(_Tp::*__pf)(_Arg) const)
Definition ahFunction.H:764
_Ret operator()(const _Tp &__r, _Arg __x) const
Definition ahFunction.H:767
const_mem_fun1_t(void(_Tp::*__pf)(_Arg) const)
Definition ahFunction.H:877
_Ret operator()(const _Tp *__p, _Arg __x) const
Definition ahFunction.H:729
_Ret(_Tp::* _M_f)(_Arg) const
Definition ahFunction.H:736
const_mem_fun1_t(_Ret(_Tp::*__pf)(_Arg) const)
Definition ahFunction.H:726
const_mem_fun_ref_t(void(_Tp::*__pf)() const)
Definition ahFunction.H:839
_Ret operator()(const _Tp &__r) const
Definition ahFunction.H:691
const_mem_fun_ref_t(_Ret(_Tp::*__pf)() const)
Definition ahFunction.H:688
_Ret(_Tp::* _M_f)() const
Definition ahFunction.H:698
const_mem_fun_t(void(_Tp::*__pf)() const)
Definition ahFunction.H:802
const_mem_fun_t(_Ret(_Tp::*__pf)() const)
Definition ahFunction.H:650
_Ret(_Tp::* _M_f)() const
Definition ahFunction.H:660
_Ret operator()(const _Tp *__p) const
Definition ahFunction.H:653
mem_fun1_ref_t(void(_Tp::*__pf)(_Arg))
Definition ahFunction.H:896
_Ret(_Tp::* _M_f)(_Arg)
Definition ahFunction.H:755
_Ret operator()(_Tp &__r, _Arg __x) const
Definition ahFunction.H:748
mem_fun1_ref_t(_Ret(_Tp::*__pf)(_Arg))
Definition ahFunction.H:745
mem_fun1_t(void(_Tp::*__pf)(_Arg))
Definition ahFunction.H:858
_Ret operator()(_Tp *__p, _Arg __x) const
Definition ahFunction.H:710
_Ret(_Tp::* _M_f)(_Arg)
Definition ahFunction.H:717
mem_fun1_t(_Ret(_Tp::*__pf)(_Arg))
Definition ahFunction.H:707
mem_fun_ref_t(void(_Tp::*__pf)())
Definition ahFunction.H:821
_Ret(_Tp::* _M_f)()
Definition ahFunction.H:679
_Ret operator()(_Tp &__r) const
Definition ahFunction.H:672
mem_fun_ref_t(_Ret(_Tp::*__pf)())
Definition ahFunction.H:669
mem_fun_t(void(_Tp::*__pf)())
Definition ahFunction.H:783
_Ret operator()(_Tp *__p) const
Definition ahFunction.H:634
mem_fun_t(_Ret(_Tp::*__pf)())
Definition ahFunction.H:631
_Ret(_Tp::* _M_f)()
Definition ahFunction.H:641
pointer_to_binary_function(_Result(*__x)(_Arg1, _Arg2))
Definition ahFunction.H:566
_Result(* _M_ptr)(_Arg1, _Arg2)
Definition ahFunction.H:560
_Result operator()(_Arg1 __x, _Arg2 __y) const
Definition ahFunction.H:569
pointer_to_unary_function(_Result(*__x)(_Arg))
Definition ahFunction.H:537
_Result operator()(_Arg __x) const
Definition ahFunction.H:540
unary_negate(const _Predicate &__x)
Definition ahFunction.H:392
bool operator()(const typename _Predicate::argument_type &__x) const noexcept(noexcept(not static_cast< bool >(_M_pred(__x))))
The negation of what the predicate says of __x.
Definition ahFunction.H:402
Whether T(x / y) compiles and cannot throw, for divides.
Definition ahFunction.H:138
Whether x == y compiles and cannot throw, for equal_to.
Definition ahFunction.H:159
Whether x >= y compiles and cannot throw, for greater_equal.
Definition ahFunction.H:180
Whether x > y compiles and cannot throw, for greater.
Definition ahFunction.H:173
Whether x <= y compiles and cannot throw, for less_equal.
Definition ahFunction.H:187
Whether x < y compiles and cannot throw, nor the conversion of its result to bool,...
Definition ahFunction.H:106
Whether x and y compiles and cannot throw, for logical_and.
Definition ahFunction.H:194
Whether not x compiles and cannot throw, for logical_not.
Definition ahFunction.H:208
Whether x or y compiles and cannot throw, for logical_or.
Definition ahFunction.H:201
Whether T(x - y) compiles and cannot throw, for minus.
Definition ahFunction.H:124
Whether T(x % y) compiles and cannot throw, for modulus.
Definition ahFunction.H:145
Whether T(x * y) compiles and cannot throw, for multiplies.
Definition ahFunction.H:131
Whether T(-x) compiles and cannot throw, for negate.
Definition ahFunction.H:152
Whether x != y compiles and cannot throw, for not_equal_to.
Definition ahFunction.H:166
Whether T(x + y) compiles and cannot throw, for plus.
Definition ahFunction.H:117
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4196
static mpfr_t y
Definition mpfr_mul_d.c:3
Main namespace for Aleph-w library functions.
mem_fun_ref_t< _Ret, _Tp > mem_fun_ref(_Ret(_Tp::*__f)())
Definition ahFunction.H:942
bool less_than(const T &op1, const T &op2, Compare &cmp)
Determines if op1 is less than op2 using a comparison operator.
Definition ahFunction.H:991
mem_fun_t< _Ret, _Tp > mem_fun(_Ret(_Tp::*__f)())
Definition ahFunction.H:930
binder2nd< _Operation > bind2nd(const _Operation &__fn, const _Tp &__x)
Definition ahFunction.H:518
std::decay_t< typename HeadC::Item_Type > T
Definition ah-zip.H:152
and
Check uniqueness with explicit hash + equality functors.
bool greater_than(const T &op1, const T &op2, Compare &&cmp=Compare())
Determines if op1 is greater than op2 using a comparison operator.
unary_negate< _Predicate > not1(const _Predicate &__pred)
Definition ahFunction.H:411
bool are_equals(const T &op1, const T &op2, Compare &&cmp=Compare())
Determines if operands are equal using a comparison operator.
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__x)(_Arg))
Definition ahFunction.H:548
binder1st< _Operation > bind1st(const _Operation &__fn, const _Tp &__x)
Definition ahFunction.H:479
bool less_or_equal_than(const T &op1, const T &op2, Compare &cmp)
Determines if op1 is less than or equal to op2 using a comparison operator.
binary_negate< _Predicate > not2(const _Predicate &__pred)
Definition ahFunction.H:441
bool greater_or_equal_than(const T &op1, const T &op2, Compare &&cmp=Compare())
Determines if op1 is greater than or equal to op2 using a comparison operator.
bool no_equals(const T &op1, const T &op2, Compare &&cmp=Compare())
Determines if operands are not equal using a comparison operator.
bool operator()(const T &op1, const T &op2) const
_Tp & operator()(_Tp &__x) const
Definition ahFunction.H:586
_Pair::first_type & operator()(_Pair &__x) const
Definition ahFunction.H:600
_Pair::second_type & operator()(_Pair &__x) const
Definition ahFunction.H:614
_Tp operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_divides< _Tp >)
Definition ahFunction.H:251
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_equal_to< _Tp >)
Definition ahFunction.H:284
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_greater_equal< _Tp >)
Definition ahFunction.H:330
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_greater< _Tp >)
Definition ahFunction.H:306
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_less_equal< _Tp >)
Definition ahFunction.H:341
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_less_than< _Tp >)
Definition ahFunction.H:319
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_logical_and< _Tp >)
Definition ahFunction.H:352
bool operator()(const _Tp &__x) const noexcept(function_detail::nothrow_logical_not< _Tp >)
Definition ahFunction.H:374
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_logical_or< _Tp >)
Definition ahFunction.H:363
_Tp operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_minus< _Tp >)
Definition ahFunction.H:229
_Tp operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_modulus< _Tp >)
Definition ahFunction.H:262
_Tp operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_multiplies< _Tp >)
Definition ahFunction.H:240
_Tp operator()(const _Tp &__x) const noexcept(function_detail::nothrow_negate< _Tp >)
Definition ahFunction.H:273
bool operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_not_equal_to< _Tp >)
Definition ahFunction.H:295
_Tp operator()(const _Tp &__x, const _Tp &__y) const noexcept(function_detail::nothrow_plus< _Tp >)
Definition ahFunction.H:218