Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions include/boost/parser/detail/text/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ namespace boost::parser::detail { namespace text {

namespace detail {
template<typename Iter>
std::ptrdiff_t distance(Iter first, Iter last, non_sentinel_tag)
std::ptrdiff_t distance(Iter const & first, Iter const & last, non_sentinel_tag)
{
return std::distance(first, last);
}

template<typename Iter, typename Sentinel>
std::ptrdiff_t distance(Iter first, Sentinel last, sentinel_tag)
std::ptrdiff_t distance(Iter first, Sentinel const & last, sentinel_tag)
{
std::ptrdiff_t retval = 0;
while (first != last) {
Expand All @@ -41,7 +41,7 @@ namespace boost::parser::detail { namespace text {
/** Range-friendly version of `std::distance()`, taking an iterator and a
sentinel. */
template<typename Iter, typename Sentinel>
std::ptrdiff_t distance(Iter first, Sentinel last)
std::ptrdiff_t distance(Iter const & first, Sentinel const & last)
{
return detail::distance(
first,
Expand All @@ -55,7 +55,7 @@ namespace boost::parser::detail { namespace text {
/** Range-friendly version of `std::find()`, taking an iterator and a
sentinel. */
template<typename BidiIter, typename Sentinel, typename T>
BidiIter find(BidiIter first, Sentinel last, T const & x)
BidiIter find(BidiIter first, Sentinel const & last, T const & x)
{
while (first != last) {
if (*first == x)
Expand All @@ -68,7 +68,7 @@ namespace boost::parser::detail { namespace text {
/** A range-friendly compliment to `std::find()`; returns an iterator to
the first element not equal to `x`. */
template<typename BidiIter, typename Sentinel, typename T>
BidiIter find_not(BidiIter first, Sentinel last, T const & x)
BidiIter find_not(BidiIter first, Sentinel const & last, T const & x)
{
while (first != last) {
if (*first != x)
Expand All @@ -81,7 +81,7 @@ namespace boost::parser::detail { namespace text {
/** Range-friendly version of `std::find_if()`, taking an iterator and a
sentinel. */
template<typename BidiIter, typename Sentinel, typename Pred>
BidiIter find_if(BidiIter first, Sentinel last, Pred p)
BidiIter find_if(BidiIter first, Sentinel const & last, Pred p)
{
while (first != last) {
if (p(*first))
Expand All @@ -94,7 +94,7 @@ namespace boost::parser::detail { namespace text {
/** Range-friendly version of `std::find_if_not()`, taking an iterator and
a sentinel. */
template<typename BidiIter, typename Sentinel, typename Pred>
BidiIter find_if_not(BidiIter first, Sentinel last, Pred p)
BidiIter find_if_not(BidiIter first, Sentinel const & last, Pred p)
{
while (first != last) {
if (!p(*first))
Expand All @@ -107,7 +107,7 @@ namespace boost::parser::detail { namespace text {
/** Analogue of `std::find()` that finds the last value in `[first, last)`
equal to `x`. */
template<typename BidiIter, typename T>
BidiIter find_backward(BidiIter first, BidiIter last, T const & x)
BidiIter find_backward(BidiIter const & first, BidiIter const & last, T const & x)
{
auto it = last;
while (it != first) {
Expand All @@ -120,7 +120,7 @@ namespace boost::parser::detail { namespace text {
/** Analogue of `std::find()` that finds the last value in `[first, last)`
not equal to `x`. */
template<typename BidiIter, typename T>
BidiIter find_not_backward(BidiIter first, BidiIter last, T const & x)
BidiIter find_not_backward(BidiIter const & first, BidiIter const & last, T const & x)
{
auto it = last;
while (it != first) {
Expand All @@ -133,7 +133,7 @@ namespace boost::parser::detail { namespace text {
/** Analogue of `std::find()` that finds the last value `v` in `[first,
last)` for which `p(v)` is true. */
template<typename BidiIter, typename Pred>
BidiIter find_if_backward(BidiIter first, BidiIter last, Pred p)
BidiIter find_if_backward(BidiIter const & first, BidiIter const & last, Pred p)
{
auto it = last;
while (it != first) {
Expand All @@ -146,7 +146,7 @@ namespace boost::parser::detail { namespace text {
/** Analogue of `std::find()` that finds the last value `v` in `[first,
last)` for which `p(v)` is false. */
template<typename BidiIter, typename Pred>
BidiIter find_if_not_backward(BidiIter first, BidiIter last, Pred p)
BidiIter find_if_not_backward(BidiIter const & first, BidiIter const & last, Pred p)
{
auto it = last;
while (it != first) {
Expand All @@ -166,7 +166,7 @@ namespace boost::parser::detail { namespace text {
the first element of the subsequence. Subranges passed to `f` are
non-overlapping. */
template<typename FwdIter, typename Sentinel, typename Func>
Func foreach_subrange(FwdIter first, Sentinel last, Func f)
Func foreach_subrange(FwdIter first, Sentinel const & last, Func f)
{
while (first != last) {
auto const & x = *first;
Expand All @@ -185,7 +185,7 @@ namespace boost::parser::detail { namespace text {
`proj(e)` each compares equal to `proj()` of the first element of the
subsequence. Subranges passed to `f` are non-overlapping. */
template<typename FwdIter, typename Sentinel, typename Func, typename Proj>
Func foreach_subrange(FwdIter first, Sentinel last, Func f, Proj proj)
Func foreach_subrange(FwdIter first, Sentinel const & last, Func f, Proj proj)
{
using value_type = typename std::iterator_traits<FwdIter>::value_type;
while (first != last) {
Expand All @@ -207,7 +207,7 @@ namespace boost::parser::detail { namespace text {
is a contiguous subsequence of elements, each of which is equal to
`x`. Subranges passed to `f` are non-overlapping. */
template<typename FwdIter, typename Sentinel, typename T, typename Func>
Func foreach_subrange_of(FwdIter first, Sentinel last, T const & x, Func f)
Func foreach_subrange_of(FwdIter first, Sentinel const & last, T const & x, Func f)
{
while (first != last) {
first = boost::parser::detail::text::find(first, last, x);
Expand All @@ -225,7 +225,7 @@ namespace boost::parser::detail { namespace text {
is a contiguous subsequence of elements `ei` for which `p(ei)` is
true. Subranges passed to `f` are non-overlapping. */
template<typename FwdIter, typename Sentinel, typename Pred, typename Func>
Func foreach_subrange_if(FwdIter first, Sentinel last, Pred p, Func f)
Func foreach_subrange_if(FwdIter first, Sentinel const & last, Pred p, Func f)
{
while (first != last) {
first = boost::parser::detail::text::find_if(first, last, p);
Expand All @@ -241,7 +241,7 @@ namespace boost::parser::detail { namespace text {

/** Sentinel-friendly version of `std::all_of()`. */
template<typename Iter, typename Sentinel, typename Pred>
bool all_of(Iter first, Sentinel last, Pred p)
bool all_of(Iter first, Sentinel const & last, Pred p)
{
for (; first != last; ++first) {
if (!p(*first))
Expand All @@ -256,7 +256,7 @@ namespace boost::parser::detail { namespace text {
typename Sentinel1,
typename Iter2,
typename Sentinel2>
bool equal(Iter1 first1, Sentinel1 last1, Iter2 first2, Sentinel2 last2)
bool equal(Iter1 first1, Sentinel1 const & last1, Iter2 first2, Sentinel2 const & last2)
{
for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
if (*first1 != *first2)
Expand All @@ -272,7 +272,7 @@ namespace boost::parser::detail { namespace text {
typename Iter2,
typename Sentinel2>
std::pair<Iter1, Iter2>
mismatch(Iter1 first1, Sentinel1 last1, Iter2 first2, Sentinel2 last2)
mismatch(Iter1 first1, Sentinel1 const & last1, Iter2 first2, Sentinel2 const & last2)
{
for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
if (*first1 != *first2)
Expand All @@ -290,7 +290,10 @@ namespace boost::parser::detail { namespace text {
typename Iter2,
typename Sentinel2>
int lexicographical_compare_three_way(
Iter1 first1, Sentinel1 last1, Iter2 first2, Sentinel2 last2)
Iter1 const & first1,
Sentinel1 const & last1,
Iter2 const & first2,
Sentinel2 const & last2)
{
auto const iters = boost::parser::detail::text::mismatch(first1, last1, first2, last2);
if (iters.first == last1) {
Expand Down
26 changes: 13 additions & 13 deletions include/boost/parser/detail/text/transcode_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace boost::parser::detail { namespace text {
typename OutIter>
transcode_result<InputIter, OutIter> transcode_utf_8_to_16(
InputIter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out,
std::input_iterator_tag)
Expand All @@ -103,7 +103,7 @@ namespace boost::parser::detail { namespace text {
template<bool UseN, typename Iter, typename OutIter>
transcode_result<Iter, OutIter> transcode_utf_8_to_16(
Iter first,
Iter last,
Iter const & last,
std::ptrdiff_t n,
OutIter out,
std::random_access_iterator_tag)
Expand All @@ -119,7 +119,7 @@ namespace boost::parser::detail { namespace text {
typename OutIter>
transcode_result<InputIter, OutIter> transcode_utf_8_to_32(
InputIter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out,
std::input_iterator_tag)
Expand All @@ -141,7 +141,7 @@ namespace boost::parser::detail { namespace text {
template<bool UseN, typename Iter, typename OutIter>
transcode_result<Iter, OutIter> transcode_utf_8_to_32(
Iter first,
Iter last,
Iter const & last,
std::ptrdiff_t n,
OutIter out,
std::random_access_iterator_tag)
Expand All @@ -158,7 +158,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_8(
tag_t<format::utf8>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand All @@ -173,7 +173,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_16(
tag_t<format::utf8>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand All @@ -189,7 +189,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_32(
tag_t<format::utf8>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand All @@ -205,7 +205,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_8(
tag_t<format::utf16>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand Down Expand Up @@ -247,7 +247,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_16(
tag_t<format::utf16>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand All @@ -261,7 +261,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_32(
tag_t<format::utf16>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand Down Expand Up @@ -304,7 +304,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_8(
tag_t<format::utf32>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand All @@ -318,7 +318,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_16(
tag_t<format::utf32>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand All @@ -332,7 +332,7 @@ namespace boost::parser::detail { namespace text {
transcode_result<Iter, OutIter> transcode_to_32(
tag_t<format::utf32>,
Iter first,
Sentinel last,
Sentinel const & last,
std::ptrdiff_t n,
OutIter out)
{
Expand Down
Loading