Why is std.algorithm so complicated to use?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 10 00:48:25 PDT 2012
On Monday, July 09, 2012 16:16:42 Andrei Alexandrescu wrote:
> > Another example:
> >
> > auto str = ["foo", "bar"].map!(x => x);
> > auto f = str.sort();
> >
> > Results in:
> >
> > http://pastebin.com/BeePWQk9
>
> The first error message is at clear as it goes:
>
> Error: r[i2] is not an lvalue
It's only clear if you go look at sort's implementation, and that failure
isn't even in sort itself! It's in its helper function, swapAt. Either sort's
template constraint should fail when it's given a range that won't work with
it, or it needs a static assertion which tells the programmer exactly what's
wrong. The fact that r[i2] isn't an lvalue means nothing without actually
digging into the code, which the average programmer should not have to do.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list