aboutsummaryrefslogtreecommitdiff
path: root/week11/Exercise05
diff options
context:
space:
mode:
Diffstat (limited to 'week11/Exercise05')
-rw-r--r--week11/Exercise05/Counted.hpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/week11/Exercise05/Counted.hpp b/week11/Exercise05/Counted.hpp
new file mode 100644
index 0000000..fe705ab
--- /dev/null
+++ b/week11/Exercise05/Counted.hpp
@@ -0,0 +1,64 @@
+#pragma once
+
+template <class T>
+class Counted {
+ T elem;
+ unsigned count;
+
+public:
+ T& GetElem();
+ unsigned GetCount();
+
+ Counted& operator++();
+ Counted operator++(int);
+ Counted& operator--();
+ Counted operator--(int);
+ Counted& operator+=(int countChange);
+ Counted& operator-=(int countChange);
+};
+
+template <class T>
+T& Counted<T>::GetElem() {
+ return elem;
+}
+
+template <class T>
+unsigned Counted<T>::GetCount() {
+ return count;
+}
+
+template <class T>
+Counted<T>& Counted<T>::operator++() {
+ ++count;
+ return *this;
+}
+
+template <class T>
+Counted<T> Counted<T>::operator++(int) {
+ count++;
+ return *this;
+}
+
+template <class T>
+Counted<T>& Counted<T>::operator--() {
+ --count;
+ return *this;
+}
+
+template <class T>
+Counted<T> Counted<T>::operator--(int) {
+ count--;
+ return *this;
+}
+
+template <class T>
+Counted<T>& Counted<T>::operator+=(int countChange) {
+ count += countChange;
+ return *this;
+}
+
+template <class T>
+Counted<T>& Counted<T>::operator-=(int countChange) {
+ count -= countChange;
+ return *this;
+}