aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 23:26:26 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 23:26:26 +0100
commitf4d71aa6e241ae59ed7d305e8aadddf9d90b2b46 (patch)
tree06ac7c54936c3ccc3b086428630bc6d1a3399cab /backend
parent07796bea15a2d5f43766f062379b63fc9e9e1b5d (diff)
make ListIterator compatible with STL algorithm
Diffstat (limited to 'backend')
-rw-r--r--backend/ListIterator.h13
-rw-r--r--backend/ListIterator.hpp5
2 files changed, 17 insertions, 1 deletions
diff --git a/backend/ListIterator.h b/backend/ListIterator.h
index 3d11806..cf14724 100644
--- a/backend/ListIterator.h
+++ b/backend/ListIterator.h
@@ -2,6 +2,8 @@
#include "backend/List.h"
+#include <iterator>
+
#include <stddef.h>
template <typename T>
@@ -10,12 +12,21 @@ class List;
template <typename T>
class ListIterator {
public:
+ // required for <algorithm> compatibility
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = T;
+ using difference_type = std::ptrdiff_t;
+ using pointer = T*;
+ using reference = T&;
+
+public:
ListIterator(ListLink<T> * & here);
public:
T & operator * () const;
- ListIterator<T> & operator ++ ();
bool operator != (const ListIterator<T> &) const;
+ ListIterator<T> & operator ++ ();
+ bool operator ! () const;
private:
ListLink<T> * here = nullptr;
diff --git a/backend/ListIterator.hpp b/backend/ListIterator.hpp
index 30a556f..45f9acc 100644
--- a/backend/ListIterator.hpp
+++ b/backend/ListIterator.hpp
@@ -45,3 +45,8 @@ bool ListIterator<T>::operator != (const ListIterator<T> & rhs) const {
return this->here != nullptr;
}
+template <typename T>
+bool ListIterator<T>::operator ! () const {
+ return this->here == nullptr;
+}
+