Shout out to D at cppcon, when talkign about ranges.

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 8 06:10:22 PDT 2015


On Thursday, 8 October 2015 at 12:35:08 UTC, Kagamin wrote:
>
> Hmm... conceptually a bidirectional range should be able to 
> iterate back and forth:
>
> void is_word_boundary(Bidi r)
> {
>     bool is_word_prev = r.re.empty ? false : isword(r.re.back);
>     bool is_word_this = r.empty ? false : isword(r.front);
>     return is_word_prev != is_word_this;
> }
>
> auto i = myrange;
> for(; !i.empty; i.popFront())
>     if( is_word_boundary(i) )
>         break;

On Thursday, 8 October 2015 at 12:53:24 UTC, Kagamin wrote:
> The backward range can have an input range interface, like 
> retro:
>
> void is_word_boundary(Bidi r)
> {
>     bool is_word_prev = r.prev.empty ? false : 
> isword(r.prev.front);
>     bool is_word_this = r.empty ? false : isword(r.front);
>     return is_word_prev != is_word_this;
> }

What you're effectively describing is a trio of iterators wrapped 
to give an interface of two linked ranges. popFront grows the 
first one and shrinks the second. I'd be interested to see how to 
construct that, given a generic range as input.


More information about the Digitalmars-d mailing list