I'm confused about ranges (input and forward in practice, in algorithms)

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 14 05:36:06 PDT 2015


On 2015-08-14 09:28, Gary Willoughby wrote:

> I was confused a lot about ranges until I realised that a range is only
> a `view` onto the data. A range is not *the* data.
>
> For example, consuming a range does not consume the underlying data or
> modify it in any way. A forward range's save method is for creating a
> copy of the view, not a copy of the underlying data. This is to allow
> two ranges to be consumed independently without affecting the data.
>
> Usually, these ranges are returned in the form of a Result struct as
> shown here:
> https://github.com/D-Programming-Language/phobos/blob/master/std/uni.d#L6517

Until you work with arrays, which is both data and a range at the same time.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list