Simple-Log  alpha-v0.7
Predicates.hpp
Go to the documentation of this file.
1 // Copyright Dominic Koepke 2021 - 2021.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // https://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef SL_LOG_PREDICATES_HPP
7 #define SL_LOG_PREDICATES_HPP
8 
9 #pragma once
10 
11 #include <algorithm>
12 #include <concepts>
13 
14 namespace sl::log
15 {
23  template <std::equality_comparable T>
24  class Equals
25  {
26  public:
27  constexpr explicit Equals(T to) :
28  m_To{ std::move(to) }
29  {
30  }
31 
32  template <std::equality_comparable_with<T> U>
33  constexpr bool operator ()(const U& other) const
34  {
35  return other == m_To;
36  }
37 
38  private:
39  T m_To;
40  };
41 
45  template <std::equality_comparable T>
46  class NotEquals
47  {
48  public:
49  constexpr explicit NotEquals(T to) :
50  m_To{ std::move(to) }
51  {
52  }
53 
54  template <std::equality_comparable_with<T> U>
55  constexpr bool operator ()(const U& other) const
56  {
57  return other != m_To;
58  }
59 
60  private:
61  T m_To;
62  };
63 
67  template <std::totally_ordered T>
68  class Less
69  {
70  public:
71  constexpr explicit Less(T to) :
72  m_To{ std::move(to) }
73  {
74  }
75 
76  template <std::totally_ordered_with<T> U>
77  constexpr bool operator ()(const U& other) const
78  {
79  return other < m_To;
80  }
81 
82  private:
83  T m_To;
84  };
85 
89  template <std::totally_ordered T>
90  class Greater
91  {
92  public:
93  constexpr explicit Greater(T to) :
94  m_To{ std::move(to) }
95  {
96  }
97 
98  template <std::totally_ordered_with<T> U>
99  constexpr bool operator ()(const U& other) const
100  {
101  return other > m_To;
102  }
103 
104  private:
105  T m_To;
106  };
107 
111  template <std::totally_ordered T>
113  {
114  public:
115  constexpr explicit LessEquals(T to) :
116  m_To{ std::move(to) }
117  {
118  }
119 
120  template <std::totally_ordered_with<T> U>
121  constexpr bool operator ()(const U& other) const
122  {
123  return other <= m_To;
124  }
125 
126  private:
127  T m_To;
128  };
129 
133  template <std::totally_ordered T>
135  {
136  public:
137  constexpr explicit GreaterEquals(T to) :
138  m_To{ std::move(to) }
139  {
140  }
141 
142  template <std::totally_ordered_with<T> U>
143  constexpr bool operator ()(const U& other) const
144  {
145  return other >= m_To;
146  }
147 
148  private:
149  T m_To;
150  };
151 
155  template <std::totally_ordered T>
156  class Between
157  {
158  public:
159  constexpr explicit Between(T one, T two) :
160  m_Low{ std::min(one, two) },
161  m_High{ std::max(two, one) }
162  {
163  }
164 
165  template <std::totally_ordered_with<T> U>
166  constexpr bool operator ()(const U& other) const
167  {
168  return m_Low < other && other < m_High;
169  }
170 
171  private:
172  T m_Low;
173  T m_High;
174  };
175 
179  template <std::totally_ordered T>
181  {
182  public:
183  constexpr explicit BetweenEquals(T one, T two) :
184  m_Low{ std::min(one, two) },
185  m_High{ std::max(two, one) }
186  {
187  }
188 
189  template <std::totally_ordered_with<T> U>
190  constexpr bool operator ()(const U& other) const
191  {
192  return m_Low <= other && other <= m_High;
193  }
194 
195  private:
196  T m_Low;
197  T m_High;
198  };
199 
201 }
202 
203 #endif
Compares less-equality-ordering with high and greater-equality-ordering with low constant at invocati...
Definition: Predicates.hpp:181
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:190
constexpr BetweenEquals(T one, T two)
Definition: Predicates.hpp:183
Compares less-ordering with high and greater-ordering with low constant at invocation.
Definition: Predicates.hpp:157
constexpr Between(T one, T two)
Definition: Predicates.hpp:159
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:166
Compares equality with constant at invocation.
Definition: Predicates.hpp:25
constexpr Equals(T to)
Definition: Predicates.hpp:27
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:33
Compares greater-equality-ordering with constant at invocation.
Definition: Predicates.hpp:135
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:143
constexpr GreaterEquals(T to)
Definition: Predicates.hpp:137
Compares greater-ordering with constant at invocation.
Definition: Predicates.hpp:91
constexpr Greater(T to)
Definition: Predicates.hpp:93
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:99
Compares less-equality-ordering with constant at invocation.
Definition: Predicates.hpp:113
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:121
constexpr LessEquals(T to)
Definition: Predicates.hpp:115
Compares less-ordering with constant at invocation.
Definition: Predicates.hpp:69
constexpr Less(T to)
Definition: Predicates.hpp:71
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:77
Compares non-equality with constant at invocation.
Definition: Predicates.hpp:47
constexpr bool operator()(const U &other) const
Definition: Predicates.hpp:55
constexpr NotEquals(T to)
Definition: Predicates.hpp:49
Definition: BasicSink.hpp:22