summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-09-25 22:23:50 +0900
committerMaxime Coste <mawww@kakoune.org>2017-10-06 13:57:54 +0800
commit18705a009707dead4a0560b3fcb976ac3e733764 (patch)
tree03c2aed80e063a832dd65fa14dd7bfb97dc96582
parentcbb6e9ea0f22b8d65e5d8c6115920487691c7e40 (diff)
Add missing operator+= and -= on utf8_iterator
Fix operator== and != that were non-const as well.
-rw-r--r--src/utf8_iterator.hh32
1 files changed, 22 insertions, 10 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,24 +63,36 @@ 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; }