Simplify end condition checking.

This commit is contained in:
Ion Gaztañaga
2026-03-20 13:02:34 +01:00
parent 57ae7a82d3
commit cf26a274e5
2 changed files with 28 additions and 36 deletions
@@ -38,8 +38,6 @@ SegIter segmented_find_if_dispatch
typedef typename traits::local_iterator local_iterator;
typedef typename traits::segment_iterator segment_iterator;
if(first == last) return last;
segment_iterator sfirst = traits::segment(first);
const segment_iterator slast = traits::segment(last);
const local_iterator lf = traits::local(first);
@@ -47,8 +45,7 @@ SegIter segmented_find_if_dispatch
if(sfirst == slast) {
const local_iterator ll = traits::local(last);
local_iterator r = (segmented_find_if)(lf, ll, pred);
if (r != ll)
return traits::compose(sfirst, r);
return traits::compose(sfirst, r);
}
else {
//First segment
@@ -69,11 +66,9 @@ SegIter segmented_find_if_dispatch
{
const local_iterator ll = traits::local(last);
const local_iterator r = (segmented_find_if)(traits::begin(sfirst), ll, pred);
if (r != ll)
return traits::compose(sfirst, r);
return traits::compose(sfirst, r);
}
}
return last;
}
template <class InpIter, class Sent, class Pred, class Tag>
@@ -83,8 +78,8 @@ segmented_find_if_dispatch(InpIter first, Sent last, Pred pred, Tag)
{
for(; first != last; ++first)
if(pred(*first))
return first;
return last;
break;
return first;
}
} // namespace detail_algo
@@ -70,8 +70,6 @@ SegIt find_last_if_scan(SegIt first, SegIt last, Pred pred,
typedef typename traits::segment_iterator segment_iterator;
typedef typename segmented_iterator_traits<local_iterator>::is_segmented_iterator is_local_seg_t;
if (first == last) return last;
SegIt result = last;
segment_iterator sfirst = traits::segment(first);
const segment_iterator slast = traits::segment(last);
@@ -80,34 +78,33 @@ SegIt find_last_if_scan(SegIt first, SegIt last, Pred pred,
const local_iterator lf = traits::local(first);
const local_iterator ll = traits::local(last);
const local_iterator r = find_last_if_scan(lf, ll, pred, is_local_seg_t(), cat);
if (r != ll)
return traits::compose(sfirst, r);
return last;
return traits::compose(sfirst, r);
}
else {
// First segment
{
const local_iterator le = traits::end(sfirst);
const local_iterator r = find_last_if_scan(traits::local(first), le, pred, is_local_seg_t(), cat);
if (r != le)
result = traits::compose(sfirst, r);
}
// Middle segments
for (++sfirst; sfirst != slast; ++sfirst) {
const local_iterator le = traits::end(sfirst);
const local_iterator r = find_last_if_scan(traits::begin(sfirst), le, pred, is_local_seg_t(), cat);
if (r != le)
result = traits::compose(sfirst, r);
}
// Last segment
{
const local_iterator ll = traits::local(last);
const local_iterator r = find_last_if_scan(traits::begin(sfirst), ll, pred, is_local_seg_t(), cat);
if (r != ll)
result = traits::compose(sfirst, r);
}
// First segment
{
const local_iterator le = traits::end(sfirst);
const local_iterator r = find_last_if_scan(traits::local(first), le, pred, is_local_seg_t(), cat);
if (r != le)
result = traits::compose(sfirst, r);
return result;
}
// Middle segments
for (++sfirst; sfirst != slast; ++sfirst) {
const local_iterator le = traits::end(sfirst);
const local_iterator r = find_last_if_scan(traits::begin(sfirst), le, pred, is_local_seg_t(), cat);
if (r != le)
result = traits::compose(sfirst, r);
}
// Last segment
{
const local_iterator ll = traits::local(last);
const local_iterator r = find_last_if_scan(traits::begin(sfirst), ll, pred, is_local_seg_t(), cat);
if (r != ll)
result = traits::compose(sfirst, r);
}
return result;
}
//////////////////////////////////////////////