Thread overview
Is there a skipOver function for InputRanges?
Oct 08
realhet
Oct 08
Dennis
Oct 08
realhet
October 08

Hello,

I wanted to use skipOver on my input range, but I ran into an error that it needs a .save method in the range.

I can't give that because it's a generator function that catches yield()s, I can't save the state of that.

What I wanted to simplify is this:

void skipWhite()
{
  while(!scanner.empty && scanner.front.src.all!isWhite)
    scanner.popFront;
}

Is there a way to do it nicer with Phobos?
Or do I have to write a popFrontWhile() template function for this? (And try not to forget it's name in the future ;)

October 08

On Tuesday, 8 October 2024 at 07:14:28 UTC, realhet wrote:

>

Is there a way to do it nicer with Phobos?

You can use find with a negated predicate: find!(x => !x.front.all!isWhite)

October 08

On Tuesday, 8 October 2024 at 10:43:31 UTC, Dennis wrote:

>

On Tuesday, 8 October 2024 at 07:14:28 UTC, realhet wrote:

>

Is there a way to do it nicer with Phobos?

You can use find with a negated predicate: find!(x => !x.front.all!isWhite)

Perfect, Thank You!

I guess skipOver is more complex, it looks ahead, it's not just for one element, that's why it needs a ForwardRange.