Forward ranges in Phobos v2

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Nov 3 00:24:11 UTC 2021


On Wed, Nov 03, 2021 at 12:18:59AM +0000, Paul Backus via Digitalmars-d wrote:
> On Wednesday, 3 November 2021 at 00:01:33 UTC, H. S. Teoh wrote:
> > The problem with manually-added tags of this sort is that people
> > forget to do it, and that leads to trouble.  Preferably, it should
> > be something already implicit in the range type itself, that does
> > not require additional effort to tag.
> > 
> > I'm kinda toying with the idea of struct == forward range, class ==
> > input range: the difference is inherent in the type itself and
> > requires no further effort beyond the decision to use a by-value
> > type vs. a by-reference type, which coincides with the decision to
> > make something an input range or a forward range.
> 
> Having input ranges implement `next` and forward ranges implement
> `head` and `tail` would also make them easy to distinguish.

That would work too, but makes the input range API no longer a subset of
the forward range API.  This would lead to code duplication in
algorithms that only require an input range but could work equally well
with a forward range.


T

-- 
Once bitten, twice cry...


More information about the Digitalmars-d mailing list