Why is std.algorithm so complicated to use?

Jacob Carlborg doob at me.com
Tue Jul 10 09:57:25 PDT 2012


On 2012-07-10 16:36, Dmitry Olshansky wrote:

> typeof to the rescue. In fact I'm not so proud of voldemort types. As
> when you need to sotre range somewhere they stand in your way for no
> benefit.

I'm not exactly sure how you mean but this is what I came up with:

import std.algorithm;
import std.traits;
import std.conv;

class Foo
{
     auto bar ()
     {
         return [3, 4].map!(x => x.to!(string));
     }

     ReturnType!(bar) x;
}

Which is just the worst idea ever. BTW I can't see how "typeof" would work.

> auto a = [5, 3, 5, 6, 8].uniq.map!(x => x.to!(string)).array;
> sort(a);
> return a;
>
> Just use the same array, it's just that sort returns a wrapper around
> array (or other range) that indicates it's sorted by predicate x. It can
> then help to reuse this information e.g. to perforam binary search etc.

Aha, I didn't know that it sorted in place.

>
> Just take an array and call sort on it like in the old days. I don't
> think that stuffing it into one liner is required.
> Again if you need an array just call array at the end that's how it's
> supposed to be.

See above.

> Dunno, to me it says SORTED in one big scary thought. Again it should
> ether check constraint or put some more useful description. e.g.
> "(functionality akin to the uniq system utility)" doesn't strike me as
> helpful.

Sure, this particular example uses a sorted array, but nothing says an 
unsorted array won't work.

Does it only handle ints. It doesn't say anything about that in the 
documentation and the example uses ints. Then it must only accept ints.

You see how stupid that is.

-- 
/Jacob Carlborg




More information about the Digitalmars-d mailing list