Aleph-w  1.9
General library for algorithms and data structures
ahFunction.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 // Functor implementations -*- C++ -*-
28 
29 /*
30  *
31  * Copyright (c) 1994
32  * Hewlett-Packard Company
33  *
34  * Permission to use, copy, modify, distribute and sell this software
35  * and its documentation for any purpose is hereby granted without fee,
36  * provided that the above copyright notice appear in all copies and
37  * that both that copyright notice and this permission notice appear
38  * in supporting documentation. Hewlett-Packard Company makes no
39  * representations about the suitability of this software for any
40  * purpose. It is provided "as is" without express or implied warranty.
41  *
42  *
43  * Copyright (c) 1996-1998
44  * Silicon Graphics Computer Systems, Inc.
45  *
46  * Permission to use, copy, modify, distribute and sell this software
47  * and its documentation for any purpose is hereby granted without fee,
48  * provided that the above copyright notice appear in all copies and
49  * that both that copyright notice and this permission notice appear
50  * in supporting documentation. Silicon Graphics makes no
51  * representations about the suitability of this software for any
52  * purpose. It is provided "as is" without express or implied warranty.
53  */
54 
55 # ifndef AHFUNCTION_H
56 # define AHFUNCTION_H
57 
58 # include <utility>
59 
60 namespace Aleph
61 {
62 
63  template <class _Arg, class _Result>
64  struct unary_function
65  {
66  typedef _Arg argument_type;
67  typedef _Result result_type;
68  };
69 
70  template <class _Arg1, class _Arg2, class _Result>
71  struct binary_function
72  {
73  typedef _Arg1 first_argument_type; // the type of the first argument
74  typedef _Arg2 second_argument_type; // the type of the second argument
75  typedef _Result result_type; // type of the return type
76  };
77 
78 
79  template <class _Tp>
80  struct plus : public binary_function<_Tp, _Tp, _Tp>
81  {
82  _Tp operator () (const _Tp& __x, const _Tp& __y) const noexcept
83  {
84  return __x + __y;
85  }
86  };
87 
88 
89  template <class _Tp>
90  struct minus : public binary_function<_Tp, _Tp, _Tp>
91  {
92  _Tp operator () (const _Tp& __x, const _Tp& __y) const noexcept
93  {
94  return __x - __y;
95  }
96  };
97 
98 
99  template <class _Tp>
100  struct multiplies : public binary_function<_Tp, _Tp, _Tp>
101  {
102  _Tp operator () (const _Tp& __x, const _Tp& __y) const noexcept
103  {
104  return __x * __y;
105  }
106  };
107 
108 
109  template <class _Tp>
110  struct divides : public binary_function<_Tp, _Tp, _Tp>
111  {
112  _Tp operator () (const _Tp& __x, const _Tp& __y) const noexcept
113  {
114  return __x / __y;
115  }
116  };
117 
118 
119  template <class _Tp>
120  struct modulus : public binary_function<_Tp, _Tp, _Tp>
121  {
122  _Tp operator () (const _Tp& __x, const _Tp& __y) const noexcept
123  {
124  return __x % __y;
125  }
126  };
127 
128 
129  template <class _Tp>
130  struct negate : public unary_function<_Tp, _Tp>
131  {
132  _Tp operator () (const _Tp& __x) const noexcept
133  {
134  return -__x;
135  }
136  };
137 
138 
139  template <class _Tp>
140  struct equal_to : public binary_function<_Tp, _Tp, bool>
141  {
142  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
143  {
144  return __x == __y;
145  }
146  };
147 
148 
149  template <class _Tp>
150  struct not_equal_to : public binary_function<_Tp, _Tp, bool>
151  {
152  bool operator()(const _Tp& __x, const _Tp& __y) const noexcept
153  {
154  return __x != __y;
155  }
156  };
157 
158 
159  template <class _Tp>
160  struct greater : public binary_function<_Tp, _Tp, bool>
161  {
162  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
163  {
164  return __x > __y;
165  }
166  };
167 
168 
169  template <class _Tp>
170  struct less : public binary_function<_Tp, _Tp, bool>
171  {
172  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
173  {
174  return __x < __y;
175  }
176  };
177 
178 
179  template <class _Tp>
180  struct greater_equal : public binary_function<_Tp, _Tp, bool>
181  {
182  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
183  {
184  return __x >= __y;
185  }
186  };
187 
188 
189  template <class _Tp>
190  struct less_equal : public binary_function<_Tp, _Tp, bool>
191  {
192  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
193  {
194  return __x <= __y;
195  }
196  };
197 
198 
199  template <class _Tp>
200  struct logical_and : public binary_function<_Tp, _Tp, bool>
201  {
202  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
203  {
204  return __x and __y;
205  }
206  };
207 
208 
209  template <class _Tp>
210  struct logical_or : public binary_function<_Tp, _Tp, bool>
211  {
212  bool operator () (const _Tp& __x, const _Tp& __y) const noexcept
213  {
214  return __x or __y;
215  }
216  };
217 
218 
219  template <class _Tp>
220  struct logical_not : public unary_function<_Tp, bool>
221  {
222  bool operator () (const _Tp& __x) const noexcept
223  {
224  return not __x;
225  }
226  };
227 
228 
229  template <class _Predicate>
230  class unary_negate
231  : public unary_function <typename _Predicate::argument_type, bool>
232  {
233  protected:
234 
235  _Predicate _M_pred;
236 
237  public:
238 
239  explicit unary_negate (const _Predicate& __x) : _M_pred(__x) {}
240 
241  bool operator () (const typename _Predicate::argument_type& __x)
242  const noexcept
243  {
244  return not _M_pred(__x);
245  }
246  };
247 
248 
249  template <class _Predicate> inline
250  unary_negate<_Predicate> not1 (const _Predicate& __pred)
251  {
252  return unary_negate<_Predicate>(__pred);
253  }
254 
255 
256  template <class _Predicate>
257  class binary_negate
258  : public binary_function<typename _Predicate::first_argument_type,
259  typename _Predicate::second_argument_type,
260  bool>
261  {
262  protected:
263 
264  _Predicate _M_pred;
265 
266  public:
267 
268  explicit binary_negate (const _Predicate& __x) : _M_pred(__x) { }
269 
270  bool
271  operator () (const typename _Predicate::first_argument_type& __x,
272  const typename _Predicate::second_argument_type& __y) const
273  {
274  return not _M_pred(__x, __y);
275  }
276  };
277 
278 
279  template <class _Predicate> inline
280  binary_negate<_Predicate> not2 (const _Predicate& __pred)
281  {
282  return binary_negate<_Predicate>(__pred);
283  }
284 
285 
286  template <class _Operation>
287  class binder1st
288  : public unary_function<typename _Operation::second_argument_type,
289  typename _Operation::result_type>
290  {
291  protected:
292 
293  _Operation op;
294 
295  typename _Operation::first_argument_type value;
296 
297  public:
298 
299  binder1st(const _Operation& __x,
300  const typename _Operation::first_argument_type& __y)
301  : op(__x), value(__y) {}
302 
303  typename _Operation::result_type
304  operator () (const typename _Operation::second_argument_type& __x) const
305  {
306  return op (value, __x);
307  }
308 
309  typename _Operation::result_type
310  operator () (typename _Operation::second_argument_type& __x) const
311  {
312  return op(value, __x);
313  }
314  };
315 
316 
317  template <class _Operation, class _Tp> inline
318  binder1st<_Operation> bind1st(const _Operation& __fn, const _Tp& __x)
319  {
320  typedef typename _Operation::first_argument_type _Arg1_type;
321 
322  return binder1st<_Operation> (__fn, _Arg1_type(__x));
323  }
324 
325  template <class _Operation>
326  class binder2nd
327  : public unary_function<typename _Operation::first_argument_type,
328  typename _Operation::result_type>
329  {
330  protected:
331 
332  _Operation op;
333 
334  typename _Operation::second_argument_type value;
335 
336  public:
337 
338  binder2nd(const _Operation& __x,
339  const typename _Operation::second_argument_type& __y)
340  : op(__x), value (__y) {}
341 
342  typename _Operation::result_type
343  operator () (const typename _Operation::first_argument_type& __x) const
344  {
345  return op (__x, value);
346  }
347 
348  typename _Operation::result_type
349  operator () (typename _Operation::first_argument_type& __x) const
350  {
351  return op (__x, value);
352  }
353  };
354 
355 
356  template <class _Operation, class _Tp> inline
357  binder2nd<_Operation> bind2nd (const _Operation& __fn, const _Tp& __x)
358  {
359  typedef typename _Operation::second_argument_type _Arg2_type;
360 
361  return binder2nd<_Operation>(__fn, _Arg2_type(__x));
362  }
363 
364 
365  template <class _Arg, class _Result>
366  class pointer_to_unary_function : public unary_function<_Arg, _Result>
367  {
368  protected:
369 
370  _Result (*_M_ptr) (_Arg);
371 
372  public:
373 
374  pointer_to_unary_function () {}
375 
376  explicit pointer_to_unary_function(_Result (*__x) (_Arg))
377  : _M_ptr (__x) {}
378 
379  _Result operator () (_Arg __x) const
380  {
381  return _M_ptr (__x);
382  }
383  };
384 
385 
386  template <class _Arg, class _Result> inline
387  pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
388  {
389  return pointer_to_unary_function<_Arg, _Result>(__x);
390  }
391 
392 
393  template <class _Arg1, class _Arg2, class _Result>
394  class pointer_to_binary_function
395  : public binary_function<_Arg1, _Arg2, _Result>
396  {
397  protected:
398 
399  _Result (*_M_ptr) (_Arg1, _Arg2);
400 
401  public:
402 
403  pointer_to_binary_function() {}
404 
405  explicit pointer_to_binary_function(_Result (*__x) (_Arg1, _Arg2))
406  : _M_ptr(__x) {}
407 
408  _Result operator () (_Arg1 __x, _Arg2 __y) const
409  {
410  return _M_ptr(__x, __y);
411  }
412  };
413 
414 
415  template <class _Arg1, class _Arg2, class _Result> inline
416  pointer_to_binary_function<_Arg1, _Arg2, _Result>
417  ptr_fun (_Result (*__x) (_Arg1, _Arg2) )
418  {
419  return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x);
420  }
421 
422  template <class _Tp>
423  struct _Identity : public unary_function<_Tp,_Tp>
424  {
425  _Tp & operator () (_Tp& __x) const
426  {
427  return __x;
428  }
429 
430  const _Tp& operator () (const _Tp& __x) const
431  {
432  return __x;
433  }
434  };
435 
436  template <class _Pair>
437  struct _Select1st : public unary_function<_Pair, typename _Pair::first_type>
438  {
439  typename _Pair::first_type& operator () (_Pair& __x) const
440  {
441  return __x.first;
442  }
443 
444  const typename _Pair::first_type& operator () (const _Pair& __x) const
445  {
446  return __x.first;
447  }
448  };
449 
450  template <class _Pair>
451  struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
452  {
453  typename _Pair::second_type& operator () (_Pair& __x) const
454  {
455  return __x.second;
456  }
457 
458  const typename _Pair::second_type& operator () (const _Pair& __x) const
459  {
460  return __x.second;
461  }
462  };
463 
464 
465  template <class _Ret, class _Tp>
466  class mem_fun_t : public unary_function<_Tp*, _Ret>
467  {
468  public:
469 
470  explicit mem_fun_t (_Ret (_Tp::*__pf) () )
471  : _M_f(__pf) {}
472 
473  _Ret operator ()(_Tp* __p) const
474  {
475  return (__p->*_M_f)();
476  }
477 
478  private:
479 
480  _Ret (_Tp::*_M_f) ();
481  };
482 
483 
484  template <class _Ret, class _Tp>
485  class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
486  {
487  public:
488 
489  explicit const_mem_fun_t (_Ret (_Tp::*__pf) () const)
490  : _M_f (__pf) {}
491 
492  _Ret operator () (const _Tp* __p) const
493  {
494  return (__p->*_M_f) ();
495  }
496 
497  private:
498 
499  _Ret (_Tp::*_M_f) () const;
500  };
501 
502 
503  template <class _Ret, class _Tp>
504  class mem_fun_ref_t : public unary_function<_Tp, _Ret>
505  {
506  public:
507 
508  explicit mem_fun_ref_t (_Ret (_Tp::*__pf)())
509  : _M_f (__pf) {}
510 
511  _Ret operator () (_Tp& __r) const
512  {
513  return (__r.*_M_f)();
514  }
515 
516  private:
517 
518  _Ret (_Tp::*_M_f) ();
519  };
520 
521 
522  template <class _Ret, class _Tp>
523  class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
524  {
525  public:
526 
527  explicit const_mem_fun_ref_t (_Ret (_Tp::*__pf)() const)
528  : _M_f (__pf) {}
529 
530  _Ret operator () (const _Tp& __r) const
531  {
532  return (__r.*_M_f)();
533  }
534 
535  private:
536 
537  _Ret (_Tp::*_M_f) () const;
538  };
539 
540 
541  template <class _Ret, class _Tp, class _Arg>
542  class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
543  {
544  public:
545 
546  explicit mem_fun1_t (_Ret (_Tp::*__pf) (_Arg))
547  : _M_f(__pf) {}
548 
549  _Ret operator () (_Tp* __p, _Arg __x) const
550  {
551  return (__p->*_M_f) (__x);
552  }
553 
554  private:
555 
556  _Ret (_Tp::*_M_f) (_Arg);
557  };
558 
559 
560  template <class _Ret, class _Tp, class _Arg>
561  class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
562  {
563  public:
564 
565  explicit const_mem_fun1_t (_Ret (_Tp::*__pf) (_Arg) const)
566  : _M_f (__pf) {}
567 
568  _Ret operator () (const _Tp* __p, _Arg __x) const
569  {
570  return (__p->*_M_f)(__x);
571  }
572 
573  private:
574 
575  _Ret (_Tp::*_M_f) (_Arg) const;
576  };
577 
578 
579  template <class _Ret, class _Tp, class _Arg>
580  class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
581  {
582  public:
583 
584  explicit mem_fun1_ref_t (_Ret (_Tp::*__pf) (_Arg))
585  : _M_f (__pf) {}
586 
587  _Ret operator () (_Tp& __r, _Arg __x) const
588  {
589  return (__r.*_M_f)(__x);
590  }
591 
592  private:
593 
594  _Ret (_Tp::*_M_f) (_Arg);
595  };
596 
597 
598  template <class _Ret, class _Tp, class _Arg>
599  class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
600  {
601  public:
602 
603  explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
604  : _M_f(__pf) {}
605 
606  _Ret operator () (const _Tp& __r, _Arg __x) const
607  {
608  return (__r.*_M_f)(__x);
609  }
610 
611  private:
612 
613  _Ret (_Tp::*_M_f) (_Arg) const;
614  };
615 
616 
617  template <class _Tp>
618  class mem_fun_t<void, _Tp> : public unary_function<_Tp*, void>
619  {
620  public:
621 
622  explicit mem_fun_t (void (_Tp::*__pf)())
623  : _M_f (__pf) {}
624 
625  void operator () (_Tp* __p) const
626  {
627  (__p->*_M_f)();
628  }
629 
630  private:
631 
632  void (_Tp::*_M_f)();
633  };
634 
635 
636  template <class _Tp>
637  class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*, void>
638  {
639  public:
640 
641  explicit const_mem_fun_t (void (_Tp::*__pf)() const)
642  : _M_f (__pf) {}
643 
644  void operator () (const _Tp* __p) const
645  {
646  (__p->*_M_f)();
647  }
648 
649  private:
650 
651  void (_Tp::*_M_f)() const;
652  };
653 
654 
655  template <class _Tp>
656  class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
657  {
658  public:
659 
660  explicit mem_fun_ref_t (void (_Tp::*__pf)()) : _M_f (__pf) {}
661 
662  void operator () (_Tp& __r) const
663  {
664  (__r.*_M_f)();
665  }
666 
667  private:
668 
669  void (_Tp::*_M_f)();
670  };
671 
672 
673  template <class _Tp>
674  class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
675  {
676  public:
677 
678  explicit const_mem_fun_ref_t (void (_Tp::*__pf) () const)
679  : _M_f (__pf) {}
680 
681  void operator () (const _Tp& __r) const
682  {
683  (__r.*_M_f) ();
684  }
685 
686  private:
687 
688  void (_Tp::*_M_f) () const;
689  };
690 
691 
692  template <class _Tp, class _Arg>
693  class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*, _Arg, void>
694  {
695  public:
696 
697  explicit mem_fun1_t(void (_Tp::*__pf) (_Arg)) : _M_f (__pf) {}
698 
699  void operator () (_Tp* __p, _Arg __x) const
700  {
701  (__p->*_M_f)(__x);
702  }
703 
704  private:
705 
706  void (_Tp::*_M_f) (_Arg);
707  };
708 
709 
710  template <class _Tp, class _Arg>
711  class const_mem_fun1_t<void, _Tp, _Arg>
712  : public binary_function<const _Tp*, _Arg, void>
713  {
714  public:
715 
716  explicit const_mem_fun1_t (void (_Tp::*__pf) (_Arg) const) : _M_f (__pf) {}
717 
718  void operator () (const _Tp* __p, _Arg __x) const
719  {
720  (__p->*_M_f)(__x);
721  }
722 
723  private:
724 
725  void (_Tp::*_M_f)(_Arg) const;
726  };
727 
728 
729  template <class _Tp, class _Arg>
730  class mem_fun1_ref_t<void, _Tp, _Arg>
731  : public binary_function<_Tp, _Arg, void>
732  {
733  public:
734 
735  explicit mem_fun1_ref_t (void (_Tp::*__pf) (_Arg)) : _M_f (__pf) {}
736 
737  void operator () (_Tp& __r, _Arg __x) const
738  {
739  (__r.*_M_f)(__x);
740  }
741 
742  private:
743 
744  void (_Tp::*_M_f) (_Arg);
745  };
746 
747 
748  template <class _Tp, class _Arg>
749  class const_mem_fun1_ref_t<void, _Tp, _Arg>
750  : public binary_function<_Tp, _Arg, void>
751  {
752  public:
753 
754  explicit const_mem_fun1_ref_t (void (_Tp::*__pf) (_Arg) const)
755  : _M_f (__pf) {}
756 
757  void operator () (const _Tp& __r, _Arg __x) const
758  {
759  (__r.*_M_f) (__x);
760  }
761 
762  private:
763 
764  void (_Tp::*_M_f)(_Arg) const;
765  };
766 
767 
768  template <class _Ret, class _Tp> inline
769  mem_fun_t<_Ret, _Tp> mem_fun (_Ret (_Tp::*__f) () )
770  {
771  return mem_fun_t<_Ret, _Tp> (__f);
772  }
773 
774  template <class _Ret, class _Tp> inline
775  const_mem_fun_t<_Ret, _Tp> mem_fun (_Ret (_Tp::*__f) () const)
776  {
777  return const_mem_fun_t<_Ret, _Tp> (__f);
778  }
779 
780  template <class _Ret, class _Tp> inline
781  mem_fun_ref_t<_Ret, _Tp> mem_fun_ref (_Ret (_Tp::*__f) ())
782  {
783  return mem_fun_ref_t<_Ret, _Tp> (__f);
784  }
785 
786  template <class _Ret, class _Tp> inline
787  const_mem_fun_ref_t<_Ret, _Tp> mem_fun_ref (_Ret (_Tp::*__f) () const)
788  {
789  return const_mem_fun_ref_t<_Ret, _Tp> (__f);
790  }
791 
792  template <class _Ret, class _Tp, class _Arg> inline
793  mem_fun1_t<_Ret, _Tp, _Arg> mem_fun (_Ret (_Tp::*__f) (_Arg))
794  {
795  return mem_fun1_t<_Ret, _Tp, _Arg> (__f);
796  }
797 
798  template <class _Ret, class _Tp, class _Arg> inline
799  const_mem_fun1_t<_Ret, _Tp, _Arg> mem_fun (_Ret (_Tp::*__f) (_Arg) const)
800  {
801  return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f);
802  }
803 
804  template <class _Ret, class _Tp, class _Arg> inline
805  mem_fun1_ref_t<_Ret, _Tp, _Arg> mem_fun_ref (_Ret (_Tp::*__f) (_Arg))
806  {
807  return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f);
808  }
809 
810  template <class _Ret, class _Tp, class _Arg> inline
811  const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
812  mem_fun_ref (_Ret (_Tp::*__f) (_Arg) const)
813  {
814  return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f);
815  }
816 
817 
824  template <class T, class Compare> inline
825 bool less_than(const T & op1, const T & op2, Compare & cmp)
826 {
827  return cmp (op1, op2);
828 }
829 
830 
835  template <class T, class Compare> inline
836 bool less_than(const T & op1, const T & op2, Compare && cmp = Compare())
837 {
838  return less_than <T, Compare> (op1, op2, cmp);
839 }
840 
841 
848  template <class T, class Compare> inline
849 bool less_or_equal_than(const T& op1, const T& op2, Compare & cmp)
850 {
851  if (cmp(op1, op2))
852  return true;
853 
854  if (cmp(op2, op1))
855  return false;
856 
857  return true;
858 }
859 
860 
865  template <class T, class Compare> inline
866 bool less_or_equal_than(const T& op1, const T& op2, Compare && cmp = Compare())
867 {
868  return less_or_equal_than<T, Compare>(op1, op2, cmp);
869 }
870 
871 
878  template <class T, class Compare> inline
879 bool greater_than(const T& op1, const T& op2, Compare && cmp = Compare())
880 {
881  return not less_or_equal_than<T, Compare>(op1, op2,
882  std::forward<Compare>(cmp));
883 }
884 
889  template <class T, class Compare> inline
890 bool greater_than(const T& op1, const T& op2, Compare & cmp)
891 {
892  return not less_or_equal_than<T, Compare> (op1, op2, cmp);
893 }
894 
901  template <class T, class Compare> inline
902 bool greater_or_equal_than(const T& op1, const T & op2,
903  Compare && cmp = Compare())
904 {
905  return not less_than<T, Compare> (op1, op2, std::forward<Compare>(cmp));
906 }
907 
912  template <class T, class Compare> inline
913 bool greater_or_equal_than(const T& op1, const T& op2, Compare & cmp)
914 {
915  return not less_than<T, Compare> (op1, op2, cmp);
916 }
917 
924  template <class T, class Compare> inline
925 bool no_equals(const T & op1, const T & op2, Compare && cmp = Compare())
926 {
927  return cmp(op1, op2) or cmp(op2, op1);
928 }
929 
934  template <class T, class Compare> inline
935 bool no_equals(const T & op1, const T & op2, Compare & cmp)
936 {
937  return cmp(op1, op2) or cmp(op2, op1);
938 }
939 
946  template <class T, class Compare> inline
947 bool are_equals(const T & op1, const T & op2, Compare && cmp = Compare())
948 {
949  return not no_equals <T, Compare> (op1, op2, std::forward<Compare>(cmp));
950 }
951 
956  template <class T, class Compare> inline
957 bool are_equals(const T & op1, const T & op2, Compare & cmp)
958 {
959  return not no_equals <T, Compare> (op1, op2, cmp);
960 }
961 
968  template <class T, class Compare>
970 {
971  Compare & cmp;
972 
973 public:
974 
975  Inversed_Compare(Compare & __cmp) noexcept : cmp(__cmp) { /* empty */ }
976 
977  Inversed_Compare(Compare && cmp = Compare()) noexcept
978  : Inversed_Compare(cmp)
979  { /* empty */ }
980 
981  bool operator () (const T & op1, const T & op2) const noexcept
982  {
983  return cmp(op2, op1);
984  }
985 };
986 
991  template <class T, class Compare>
992 struct Compare_Dup
993 {
994  bool operator () (const T & op1, const T & op2) const
995  {
996  if (Compare () (op1, op2))
997  return true;
998 
999  if (Compare () (op2, op1))
1000  return false;
1001 
1002  return true;
1003  }
1004 };
1005 
1006 } // namespace Aleph
1007 
1008 #endif /* AHFUNCTION_H */
1009 
1010 
Definition: ah-comb.H:35
Definition: ahFunction.H:969

Leandro Rabindranath León