[phobos] bug in map

kenji hara k.hara.pg at gmail.com
Mon Aug 6 17:26:43 PDT 2012


It seems to me that is an old bug.
https://github.com/D-Programming-Language/phobos/commit/3e6679b2973069ba9191da16fd74d8b8b80865eb#L1L437

Regards.

Kenji Hara

2012/8/7 Andrei Alexandrescu <andrei at erdani.com>:
> 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
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list