diff --git a/core/cont/inc/ROOT/TSeq.hxx b/core/cont/inc/ROOT/TSeq.hxx index 7e30f7a6a4418..ae2eeebbb1d8e 100644 --- a/core/cont/inc/ROOT/TSeq.hxx +++ b/core/cont/inc/ROOT/TSeq.hxx @@ -92,33 +92,37 @@ namespace ROOT { T operator*() const { return fCounter; } - iterator &operator++() { - fCounter += fStep; - return *this; - }; - iterator operator++(int) { - iterator tmp(*this); - operator++(); - return tmp; - } + // equality bool operator==(const iterator &other) const { return fCounter == other.fCounter; } + // inequality bool operator!=(const iterator &other) const { return fCounter != other.fCounter; } - T operator+(int v) const { - return fCounter + v; + // sum with integer + iterator operator+(difference_type v) const { + return iterator(fCounter + v * fStep, fStep); } - T operator-(int v) const { - return fCounter - v; + // difference with integer + iterator operator-(difference_type v) const { + return iterator(fCounter - v * fStep, fStep); } - T operator+(const iterator &other) const { - return fCounter + other.fCounter; + // distance + difference_type operator-(const iterator &other) const { + return (fCounter - other.fCounter) / fStep; + } + // increments + iterator &operator++() { + fCounter += fStep; + return *this; } - T operator-(const iterator &other) const { - return fCounter - other.fCounter; + iterator operator++(int) { + iterator tmp(*this); + operator++(); + return tmp; } + // decrements iterator &operator--() { fCounter -= fStep; return *this; @@ -128,6 +132,15 @@ namespace ROOT { operator--(); return tmp; } + // compound assignments + iterator &operator+=(const difference_type& v) { + *this = *this + v; + return *this; + } + iterator &operator-=(const difference_type& v) { + *this = *this - v; + return *this; + } }; iterator begin() const { @@ -135,7 +148,7 @@ namespace ROOT { } iterator end() const { auto isStepMultiple = (fEnd - fBegin) % fStep == 0; - auto theEnd = isStepMultiple ? fEnd : fStep * ((T)((fEnd - fBegin) / fStep) + 1) + fBegin; + auto theEnd = isStepMultiple ? fEnd : fStep * (((fEnd - fBegin) / fStep) + 1) + fBegin; return iterator(theEnd, fStep); }