Why is std.algorithm so complicated to use?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jul 10 09:22:30 PDT 2012


On 7/10/12 12:01 PM, Christophe Travert wrote:
> Andrei Alexandrescu , dans le message (digitalmars.D:171717), a écrit :
>> auto singletonRange(E)(E value)
>> {
>>       return repeat(value).takeExactly(1);
>> }
>
> It would be much better to use:
>
> auto singletonRange(E)(E value)
> {
>       return repeat(value).takeOne;
> }
>
> as well as:
>
> auto emptyRange(E)(E value)
> {
>    return repeat(value).takeNone;
> }
>
> to have the advantages of takeOne and takeNone over takeExactly.

Ah, such as them being random access. Cool!

That also seems to answer Jonathan's quest about defining emptyRange. 
Just use takeNone(R.init).


Andrei


More information about the Digitalmars-d mailing list