All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
infinity.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_INFINITY_HPP
16 #define PAAL_INFINITY_HPP
17 
18 namespace paal {
19 
20 namespace detail {
21 
27 template <bool sign> class infinity {
28  // this is used to disable some operators overloads to remove disambiguities
29  template <typename T>
30  using disable_other_infinity = typename std::enable_if<!std::is_same<
31  typename std::decay<T>::type, infinity<!sign>>::value>::type;
32 
33  public:
35  template <typename T> bool operator<(T &&) const { return !sign; }
36 
38  bool operator<(infinity) const { return false; }
39 
41  template <typename T> bool operator>(T &&) const { return sign; }
42 
44  bool operator>(infinity) const { return false; }
45 
47  template <typename T> bool operator<=(T &&t) const {
48  return !(*this > std::forward<T>(t));
49  }
50 
52  bool operator<=(infinity) const { return true; }
53 
55  template <typename T> bool operator>=(T &&t) const {
56  return !(*this < std::forward<T>(t));
57  }
58 
60  bool operator>=(infinity) const { return true; }
61 
63  template <typename T, typename = disable_other_infinity<T>>
64  friend bool operator<(T &&t, infinity) {
65  return infinity{}
66  > std::forward<T>(t);
67  }
68 
70  template <typename T, typename = disable_other_infinity<T>>
71  friend bool operator>(T &&t, infinity) {
72  return infinity{}
73  < std::forward<T>(t);
74  }
75 
77  template <typename T, typename = disable_other_infinity<T>>
78  friend bool operator<=(T &&t, infinity) {
79  return infinity{}
80  >= std::forward<T>(t);
81  }
82 
84  template <typename T, typename = disable_other_infinity<T>>
85  friend bool operator>=(T &&t, infinity) {
86  return infinity{}
87  <= std::forward<T>(t);
88  }
89 };
90 
91 template <bool sign> bool operator<(infinity<!sign>, infinity<sign>) {
92  return sign;
93 }
94 
95 template <bool sign> bool operator>(infinity<sign>, infinity<!sign>) {
96  return sign;
97 }
98 
99 template <bool sign>
100 bool operator<=(infinity<!sign> left, infinity<sign> right) {
101  return !(left > right);
102 }
103 
104 template <bool sign>
105 bool operator>=(infinity<!sign> left, infinity<sign> right) {
106  return !(left < right);
107 }
108 
109 }
110 
113 
114 }
115 
116 #endif // PAAL_INFINITY_HPP
friend bool operator>=(T &&t, infinity)
friend operator&gt;=
Definition: infinity.hpp:85
bool operator>(T &&) const
operator&gt;
Definition: infinity.hpp:41
bool operator<=(infinity) const
operator&lt;=
Definition: infinity.hpp:52
friend bool operator<(T &&t, infinity)
friend operator&lt;
Definition: infinity.hpp:64
bool operator>(infinity) const
operator&gt;
Definition: infinity.hpp:44
bool operator<=(T &&t) const
operator&lt;=
Definition: infinity.hpp:47
bool operator>=(const fraction< A, B > &f1, const fraction< C, D > &f2)
operator&gt;=
Definition: fraction.hpp:111
bool operator<(T &&) const
operator&lt;
Definition: infinity.hpp:35
bool operator<(infinity) const
operator&lt;
Definition: infinity.hpp:38
friend bool operator>(T &&t, infinity)
friend operator&gt;
Definition: infinity.hpp:71
friend bool operator<=(T &&t, infinity)
friend operator&lt;=
Definition: infinity.hpp:78
if the sign = true, class represents plus_infinity: object bigger than everything if the sign = false...
Definition: infinity.hpp:27
bool operator>=(T &&t) const
operator&gt;=
Definition: infinity.hpp:55
bool operator>=(infinity) const
operator&gt;=
Definition: infinity.hpp:60