From 18705a009707dead4a0560b3fcb976ac3e733764 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 25 Sep 2017 22:23:50 +0900 Subject: [PATCH] Add missing operator+= and -= on utf8_iterator Fix operator== and != that were non-const as well. --- src/utf8_iterator.hh | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/utf8_iterator.hh b/src/utf8_iterator.hh index 20dc0b83..b2563e43 100644 --- a/src/utf8_iterator.hh +++ b/src/utf8_iterator.hh @@ -63,26 +63,38 @@ public: iterator operator+(DifferenceType count) const noexcept { - if (count < 0) - return operator-(-count); - iterator res = *this; - while (count--) - ++res; + res += count; return res; } + iterator& operator+=(DifferenceType count) noexcept + { + if (count < 0) + return operator-=(-count); + + while (count--) + operator++(); + return *this; + } + iterator operator-(DifferenceType count) const noexcept { - if (count < 0) - return operator+(-count); - iterator res = *this; - while (count--) - --res; + res -= count; return res; } + iterator& operator-=(DifferenceType count) noexcept + { + if (count < 0) + return operator+=(-count); + + while (count--) + operator--(); + return *this; + } + bool operator==(const iterator& other) const noexcept { return m_it == other.m_it; } bool operator!=(const iterator& other) const noexcept { return m_it != other.m_it; } @@ -92,8 +104,8 @@ public: bool operator> (const iterator& other) const noexcept { return m_it > other.m_it; } bool operator>= (const iterator& other) const noexcept { return m_it >= other.m_it; } - bool operator==(const BaseIt& other) noexcept { return m_it == other; } - bool operator!=(const BaseIt& other) noexcept { return m_it != other; } + bool operator==(const BaseIt& other) const noexcept { return m_it == other; } + bool operator!=(const BaseIt& other) const noexcept { return m_it != other; } bool operator< (const BaseIt& other) const noexcept { return m_it < other; } bool operator<= (const BaseIt& other) const noexcept { return m_it <= other; }