Skip to content

Commit 6b0b722

Browse files
Add a drop function for ranget
This is useful for advancing the range without having to manipulate the private `begin_value` field.
1 parent 9468913 commit 6b0b722

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/util/range.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ struct ranget final
341341
return begin_value == end_value;
342342
}
343343

344+
/// Drop the first \p count elements.
345+
/// If the range has fewer elements, drops everything.
346+
/// \return true if the range still contains element after the drop
347+
bool drop(std::size_t count)
348+
{
349+
for(std::size_t i = 0; i < count; ++i)
350+
{
351+
if(begin_value == end_value)
352+
return false;
353+
++begin_value;
354+
}
355+
return begin_value != end_value;
356+
}
357+
344358
iteratort begin() const
345359
{
346360
return begin_value;

0 commit comments

Comments
 (0)