Skip to content

Commit

Permalink
Add retreat counterpart of advance
Browse files Browse the repository at this point in the history
`prior` is to `next` what `retreat` is to `advance`
  • Loading branch information
glebm committed Nov 28, 2018
1 parent 7e51e1c commit 45f6a9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/utf8/checked.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ namespace utf8
utf8::next(it, end);
}

template <typename octet_iterator, typename distance_type>
void retreat (octet_iterator& it, distance_type n, octet_iterator end)
{
for (distance_type i = 0; i < n; ++i)
utf8::prior(it, end);
}

template <typename octet_iterator>
typename std::iterator_traits<octet_iterator>::difference_type
distance (octet_iterator first, octet_iterator last)
Expand Down
7 changes: 7 additions & 0 deletions source/utf8/unchecked.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ namespace utf8
utf8::unchecked::next(it);
}

template <typename octet_iterator, typename distance_type>
void retreat (octet_iterator& it, distance_type n)
{
for (distance_type i = 0; i < n; ++i)
utf8::unchecked::prior(it);
}

template <typename octet_iterator>
typename std::iterator_traits<octet_iterator>::difference_type
distance (octet_iterator first, octet_iterator last)
Expand Down

0 comments on commit 45f6a9a

Please sign in to comment.