Why is std.algorithm so complicated to use?

Timon Gehr timon.gehr at gmx.ch
Tue Jul 10 09:44:01 PDT 2012


On 07/10/2012 06:38 PM, Jacob Carlborg wrote:
> On 2012-07-10 17:30, Andrei Alexandrescu wrote:
>
>> It would be possible to chain a single element to the end of a range.
>> One related thing to do is to define singletonRange(x) that returns a
>> range with exactly one element, namely x.
>
> Ok, I saw that suggestion in another post.
>
>> Ranges and std.algorithm obey simple, mathematical realities deriving
>> from algorithm and storage topology constraints. For example sort works
>> in place so it generally can't work on mapped stuff because there's no
>> place to put the sorted contents. Also sort needs a random-access range
>> to work with so it can't work e.g. with the result of filter, which
>> necessarily yields a non-random-access range. And so on.
>
> Can't "map" and "filter" return a random-access range if that's what
> they receive?
>

Map can do that and does do that. How would it work for filter?


More information about the Digitalmars-d mailing list