@@ -26,7 +26,7 @@ namespace Nemea {
2626 *
2727 * @tparam T The type of the values in the array.
2828 */
29- template <typename T>
29+ template <typename T>
3030class UnirecArray {
3131public:
3232 /* *
@@ -45,25 +45,63 @@ class UnirecArray {
4545 {
4646 }
4747
48+ // Dereference
4849 reference operator *() const { return *m_ptr; }
49- pointer operator ->() { return m_ptr; }
50+ pointer operator ->() const { return m_ptr; }
51+
52+ // Increment / Decrement
5053 Iterator& operator ++()
5154 {
52- m_ptr++ ;
55+ ++m_ptr ;
5356 return *this ;
5457 }
55-
5658 Iterator operator ++(int )
5759 {
5860 Iterator tmp = *this ;
5961 ++(*this );
6062 return tmp;
6163 }
64+ Iterator& operator --()
65+ {
66+ --m_ptr;
67+ return *this ;
68+ }
69+ Iterator operator --(int )
70+ {
71+ Iterator tmp = *this ;
72+ --(*this );
73+ return tmp;
74+ }
75+
76+ // Arithmetic
77+ Iterator operator +(difference_type n) const { return Iterator (m_ptr + n); }
78+ Iterator operator -(difference_type n) const { return Iterator (m_ptr - n); }
79+ difference_type operator -(const Iterator& other) const { return m_ptr - other.m_ptr ; }
80+
81+ Iterator& operator +=(difference_type n)
82+ {
83+ m_ptr += n;
84+ return *this ;
85+ }
86+ Iterator& operator -=(difference_type n)
87+ {
88+ m_ptr -= n;
89+ return *this ;
90+ }
91+
92+ // Comparison
93+ bool operator ==(const Iterator& other) const { return m_ptr == other.m_ptr ; }
94+ bool operator !=(const Iterator& other) const { return m_ptr != other.m_ptr ; }
95+ bool operator <(const Iterator& other) const { return m_ptr < other.m_ptr ; }
96+ bool operator <=(const Iterator& other) const { return m_ptr <= other.m_ptr ; }
97+ bool operator >(const Iterator& other) const { return m_ptr > other.m_ptr ; }
98+ bool operator >=(const Iterator& other) const { return m_ptr >= other.m_ptr ; }
6299
63- T* data () { return m_ptr; }
100+ // Indexing
101+ reference operator [](difference_type n) const { return *(m_ptr + n); }
64102
65- bool operator ==( const Iterator& other) const { return this -> m_ptr == other. m_ptr ; };
66- bool operator !=( const Iterator& other) const { return this -> m_ptr != other. m_ptr ; };
103+ // Data pointer access
104+ pointer data () { return m_ptr; }
67105
68106 private:
69107 pointer m_ptr;
0 commit comments