[phobos] bug in map

Andrei Alexandrescu andrei at erdani.com
Mon Aug 6 11:55:56 PDT 2012


Consider:

auto s = "some string";
static assert(!hasLength(typeof(s));
auto m = map!(a => a)(s);
static assert(!hasLength(typeof(s));

Both asserts should pass: string famously has a length that's actually 
not the length of the range. Then mapping something on top of the string 
should also have no meaningful length. Alas, it does, because of the 
following code in std.algorithm:

static if (hasLength!R || isSomeString!R)
{
     @property auto length()
     {
          return _input.length;
     }
     alias length opDollar;
}

The code used to introduce length only if if (hasLength!R).

It seems Kenji introduced this change. What was its purpose, and can we 
undo it? This breaks the entire web of assumptions that hasLength builds.


Thanks,

Andrei


More information about the phobos mailing list