foreach range with index
Luís Marques via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jun 13 20:03:36 PDT 2017
On Wednesday, 14 June 2017 at 02:48:34 UTC, Luís Marques wrote:
> Hmm, I suppose that even if we have all of the good stuff of
> length, opIndex, opSlice, etc., we can't assume the indices are
> [0..length], right? But there should be some way for, say, map
> to preserve that information from the slice, the same way
> random access is preserved.
A quick look into std.algorithm.iteration suggests that this is
not actually true. For instance:
static if (hasLength!R)
{
foreach (k; 0 .. data.length / 16)
So I guess we are assuming that if we have length then indexing
is always [0..length]. These are the kinds of details that I
never know because there is no spec for ranges :(
More information about the Digitalmars-d
mailing list