diff --git a/src/container/iterator.hpp b/src/container/iterator.hpp new file mode 100644 index 0000000..4f0ad3a --- /dev/null +++ b/src/container/iterator.hpp @@ -0,0 +1,31 @@ +#pragma once + +namespace gz { + +/** + * @brief A generic iterator that satisfies std::forward_iterator + */ +template +struct Iterator { + public: + using value_type = T; + Iterator() : ptr(nullptr) {}; + Iterator(T* ptr) : ptr(ptr) {}; + T& operator*() const { return *ptr; }; + Iterator& operator=(const Iterator& other) { + ptr = other.ptr; + return *this; + }; + Iterator& operator++() { ptr += sizeof(T); return *this; }; + Iterator operator++(int) { auto copy = *this; ptr += sizeof(T); return copy; }; + friend int operator-(Iterator lhs, Iterator rhs) { + return lhs.ptr - rhs.ptr; + }; + bool operator==(const Iterator& other) const { return ptr == other.ptr; }; + // bool operator!=(const Iterator& other) const { return ptr != other.ptr; }; + private: + T* ptr; +}; // Iterator + +/* static_assert(std::forward_iterator>, "Iterator not a forward range."); */ +} // namespace gz