diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-14 19:59:06 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-14 19:59:06 +0300 |
commit | dad59528ccd770301b29c7db8148ff8ab8e89c92 (patch) | |
tree | b93aa1b9149ddf20d6317d44cf924be8d0be276a /include/m_system_cpp.h | |
parent | 1a3f9ca88310cb9080a4c0073087bebc4c1e3a0a (diff) |
reverse iterators for LIST<>
Diffstat (limited to 'include/m_system_cpp.h')
-rw-r--r-- | include/m_system_cpp.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index c6bd65a25d..10acdebde4 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -196,6 +196,35 @@ template<class T> struct LIST return (!List_GetIndex((SortedList*)this, p, &idx)) ? -1 : idx;
}
+ class reverse_iterator
+ {
+ int index;
+ T **base;
+
+ public:
+ reverse_iterator(const LIST &_lst) :
+ index(_lst.getCount()),
+ base(_lst.getArray())
+ {
+ if (index > 0)
+ index--;
+ }
+
+ class iterator
+ {
+ T** ptr;
+
+ public:
+ iterator(T **_p) : ptr(_p) {}
+ iterator operator++() { --ptr; return *this; }
+ bool operator!=(const iterator &p) { return ptr != p.ptr; }
+ operator T**() const { return ptr; }
+ };
+
+ __inline iterator begin() const { return iterator(base + index); }
+ __inline iterator end() const { return iterator(base); }
+ };
+
__inline void destroy(void) { List_Destroy((SortedList*)this); }
__inline T* find(T *p) const { return (T*)List_Find((SortedList*)this, p); }
__inline int indexOf(T *p) const { return List_IndexOf((SortedList*)this, p); }
@@ -210,6 +239,8 @@ template<class T> struct LIST __inline T** begin() const { return items; }
__inline T** end() const { return items + count; }
+ __inline reverse_iterator rev_iter() const { return reverse_iterator(*this); }
+
protected:
T** items;
int count, limit, increment;
|