[phobos] Fixing Map

Andrei Alexandrescu andrei at erdani.com
Sun Jan 2 17:14:11 PST 2011


On 9/17/10 10:00 PM, David Simcha wrote:
> I'm thinking about improving/fixing std.algorithm.Map. Two things I want
> to bounce off other Phobos devs:
>
> 1. Should we just dump the cache? I can't think of any other reasonable
> way to fix http://d.puremagic.com/issues/show_bug.cgi?id=4798 . In real
> world use cases the mapping function is cheap, and if not people will
> probably just call array() to do it eagerly.

Fortunately I dumped it already. It's caused more trouble than good.

> 2. Should Map return by ref if possible? This would enable idioms like
> this:
>
> struct S {
> uint a, b, c;
> }
>
> ref uint getA(ref S s) { return s.a; }
>
> auto sArray = new S[42];
> sort(map!getA(sArray));

Good question. I think that's worth pursuing.


Andrei


More information about the phobos mailing list