commit 4bf4a9f186a7456b8b15f2676de458afed3afdb0
parent 32a1ce441b1a2e8874c7c3b9d3042fc79a35feb4
Author: Oshgnacknak <osh@oshgnacknak.de>
Date: Wed, 26 Jan 2022 23:26:59 +0100
Move utility procedures to the bottom
Diffstat:
M | osh.h | | | 43 | +++++++++++++++++++++++++++---------------- |
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/osh.h b/osh.h
@@ -5,12 +5,6 @@
namespace osh {
- template<typename T>
- T min(T a, T b);
-
- template<typename T>
- T max(T a, T b);
-
template<typename T, typename P>
concept PrintableTo = requires(T t, P p) {
print1(p, t);
@@ -110,8 +104,16 @@ namespace osh {
void print1(Formatter auto&, const StringBuffer&);
+ int listIndex(int index, const int& size);
+
template<typename T>
void swap(T& a, T& b);
+
+ template<typename T>
+ T min(T a, T b);
+
+ template<typename T>
+ T max(T a, T b);
}
#endif /* OSH_H */
@@ -123,16 +125,6 @@ namespace osh {
namespace osh {
- template<typename T>
- T min(T a, T b) {
- return a < b ? a : b;
- }
-
- template<typename T>
- T max(T a, T b) {
- return a > b ? a : b;
- }
-
void print1(Formatter auto& fmt, const char* s) {
fmt.format("%s", s);
}
@@ -345,7 +337,16 @@ namespace osh {
template<typename T>
void checkIndex(const T& index, const T& size) {
assert(index >= 0 && index < size,
+
+ int listIndex(int index, const int& size) {
+ assert(index >= -size && index < size,
"Index", index, "out of bounce");
+
+ if (index < 0) {
+ index += size;
+ }
+
+ return index;
}
template<typename T>
@@ -354,6 +355,16 @@ namespace osh {
a = b;
b = t;
}
+
+ template<typename T>
+ T min(T a, T b) {
+ return a < b ? a : b;
+ }
+
+ template<typename T>
+ T max(T a, T b) {
+ return a > b ? a : b;
+ }
}
#endif // OSH_H_IMPLEMENTATION