Why is std.algorithm so complicated to use?

Jacob Carlborg doob at me.com
Mon Jul 9 23:50:20 PDT 2012


On 2012-07-09 22:16, Andrei Alexandrescu wrote:

> So foo is a range of strings, because each element of it is a string.
> Then you want to chain a range of strings with a string, which is a
> range of dchar. That doesn't work, and I agree the error message should
> be more informative.

Is that by design or something that can be fixed?

> To fix the example, write
>
> auto bar = foo.chain(["bar"]);

I think that's an ugly workaround.

>> 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

"Clear as it goes" WTF? Are you nuts? It's an insanly bad error message, 
I have no "r" in my code. Is it too much to ask to be able to sort a range?

This just proves that std.algorithm is complicated to use. It's very 
unintuitive.

What I really want is this, but ranges doesn't work like that:

Foo f = Foo();
Foo[] foos = [f];
string[] = foos.map!(x => "foo");
string[] bar = foo ~= "foo";

And:

string[] str = ["foo", "bar"].map!(x => x);
string[] f = str.sort();

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list