range behaviour

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue May 13 09:58:09 PDT 2014


On Tue, 13 May 2014 18:38:44 +0200
Benjamin Thaut via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> I know that there was a recent discussion about how the methods of
> ranges should behave.
>
> E.g.
>
> - Does empty always have to be called before calling front or
> popFront?

Certainly, ranges are pretty much always used this way, but there was some
debate as to whether empty could have work done in it (and thus _had_ to be
called). However, I believe that the consensus was that yes, empty had to be
called (certainly, both Walter and Andrei felt that way).

> - Is it allowed to call front multiple times between two calls to
> popFront?

Definitely. _Lots_ of range-based code would break otherwise - though there
are casese where that can cause problems depending on what you rely on (e.g.
map!(a => to!string(a)) will return equal strings, but they aren't the _same_
string).

> Was there a result of that discussion? Is it documented somewhere?

AFAIK, there's just the semi-recent newsgroup discussion on the matter, though
maybe someone put something up on the wiki.

- Jonathan M Davis


More information about the Digitalmars-d mailing list