aboutsummaryrefslogtreecommitdiffstats
path: root/src/tag/Tag.hxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tag/Tag.hxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx
index 5d3aaad0c..74221417f 100644
--- a/src/tag/Tag.hxx
+++ b/src/tag/Tag.hxx
@@ -25,6 +25,7 @@
#include "Compiler.h"
#include <algorithm>
+#include <iterator>
#include <stddef.h>
@@ -136,6 +137,59 @@ struct Tag {
*/
gcc_pure
bool HasType(TagType type) const;
+
+ class const_iterator {
+ friend struct Tag;
+ const TagItem *const*cursor;
+
+ constexpr const_iterator(const TagItem *const*_cursor)
+ :cursor(_cursor) {}
+
+ public:
+ constexpr const TagItem &operator*() const {
+ return **cursor;
+ }
+
+ constexpr const TagItem *operator->() const {
+ return *cursor;
+ }
+
+ const_iterator &operator++() {
+ ++cursor;
+ return *this;
+ }
+
+ const_iterator operator++(int) {
+ auto result = cursor++;
+ return const_iterator{result};
+ }
+
+ const_iterator &operator--() {
+ --cursor;
+ return *this;
+ }
+
+ const_iterator operator--(int) {
+ auto result = cursor--;
+ return const_iterator{result};
+ }
+
+ constexpr bool operator==(const_iterator other) const {
+ return cursor == other.cursor;
+ }
+
+ constexpr bool operator!=(const_iterator other) const {
+ return cursor != other.cursor;
+ }
+ };
+
+ const_iterator begin() const {
+ return const_iterator{items};
+ }
+
+ const_iterator end() const {
+ return const_iterator{items + num_items};
+ }
};
/**