|
|
@@ -0,0 +1,56 @@
|
|
|
+#pragma once
|
|
|
+
|
|
|
+namespace types {
|
|
|
+ template <typename Self>
|
|
|
+ struct Incrementable {
|
|
|
+ friend Self operator++(Self const & self, int) {
|
|
|
+ Self copy = self;
|
|
|
+ self = Self(self.get() + 1);
|
|
|
+ return copy;
|
|
|
+ }
|
|
|
+ friend Self & operator++(Self const & self) {
|
|
|
+ return self = Self(self.get() + 1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Self>
|
|
|
+ struct Decrementable {
|
|
|
+ friend Self operator--(Self const & self, int) {
|
|
|
+ Self copy = self;
|
|
|
+ self = Self(self.get() - 1);
|
|
|
+ return copy;
|
|
|
+ }
|
|
|
+ friend Self & operator--(Self const & self) {
|
|
|
+ return self = Self(self.get() - 1);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Self>
|
|
|
+ struct Addable {
|
|
|
+ friend Self operator+(Self const & lhs, Self const & rhs) {
|
|
|
+ return Self(lhs.get() + rhs.get());
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Self>
|
|
|
+ struct Arithmatic : Addable<Self> {
|
|
|
+ friend Self operator-(Self const & self) {
|
|
|
+ return Self(-self.get());
|
|
|
+ }
|
|
|
+
|
|
|
+ friend Self operator-(Self const & lhs, Self const & rhs) {
|
|
|
+ return Self(lhs.get() - rhs.get());
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Self>
|
|
|
+ struct Numeric : Arithmatic<Self> {
|
|
|
+ friend Self operator*(Self const & lhs, Self const & rhs) {
|
|
|
+ return Self(lhs.get() * rhs.get());
|
|
|
+ }
|
|
|
+
|
|
|
+ friend Self operator/(Self const & lhs, Self const & rhs) {
|
|
|
+ return Self(lhs.get() / rhs.get());
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|