From 18705a009707dead4a0560b3fcb976ac3e733764 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 25 Sep 2017 22:23:50 +0900 Subject: Add missing operator+= and -= on utf8_iterator Fix operator== and != that were non-const as well. --- src/utf8_iterator.hh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src') 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 @@ -62,25 +62,37 @@ public: } iterator operator+(DifferenceType count) const noexcept + { + iterator res = *this; + res += count; + return res; + } + + iterator& operator+=(DifferenceType count) noexcept { if (count < 0) - return operator-(-count); + return operator-=(-count); - iterator res = *this; while (count--) - ++res; - return res; + operator++(); + return *this; } iterator operator-(DifferenceType count) const noexcept + { + iterator res = *this; + res -= count; + return res; + } + + iterator& operator-=(DifferenceType count) noexcept { if (count < 0) - return operator+(-count); + return operator+=(-count); - iterator res = *this; while (count--) - --res; - return res; + operator--(); + return *this; } 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; } -- cgit v1.2.3