diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-10-31 19:41:12 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-11-01 08:22:43 +1100 |
| commit | 4cfb46ff2e6c63c28c1881b366e33d817c45b637 (patch) | |
| tree | 1b1e86f9893a277e28cd9352b083b8a38ea88ffb /src/utf8_iterator.hh | |
| parent | 9fec1b3fafe4a9a3126e203ee01045ed4ae15aba (diff) | |
Support different type for iterators and sentinel in utf8 functions
Diffstat (limited to 'src/utf8_iterator.hh')
| -rw-r--r-- | src/utf8_iterator.hh | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/utf8_iterator.hh b/src/utf8_iterator.hh index 20386069..c145f900 100644 --- a/src/utf8_iterator.hh +++ b/src/utf8_iterator.hh @@ -14,6 +14,7 @@ namespace utf8 // adapter for an iterator on bytes which permits to iterate // on unicode codepoints instead. template<typename BaseIt, + typename Sentinel = BaseIt, typename CodepointType = Codepoint, typename DifferenceType = CharCount, typename InvalidPolicy = utf8::InvalidPolicy::Pass> @@ -25,7 +26,7 @@ public: iterator() = default; constexpr static bool noexcept_policy = noexcept(InvalidPolicy{}(0)); - iterator(BaseIt it, BaseIt begin, BaseIt end) noexcept + iterator(BaseIt it, Sentinel begin, Sentinel end) noexcept : m_it{std::move(it)}, m_begin{std::move(begin)}, m_end{std::move(end)} {} @@ -105,8 +106,13 @@ 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) const noexcept { return m_it == other; } - bool operator!=(const BaseIt& other) const noexcept { return m_it != other; } + template<typename T> + std::enable_if_t<std::is_same<T, BaseIt>::value or std::is_same<T, Sentinel>::value, bool> + operator==(const T& other) const noexcept { return m_it == other; } + + template<typename T> + std::enable_if_t<std::is_same<T, BaseIt>::value or std::is_same<T, Sentinel>::value, bool> + operator!=(const T& 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; } @@ -136,8 +142,8 @@ private: } BaseIt m_it; - BaseIt m_begin; - BaseIt m_end; + Sentinel m_begin; + Sentinel m_end; mutable CodepointType m_value = -1; }; |
