.sort vs sort(): std.algorithm not up to the task?

Andrew Edwards via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 7 18:57:47 PDT 2017


Ranges may be finite or infinite but, while the destination may 
be unreachable, we can definitely tell how far we've traveled. So 
why doesn't this work?

import std.traits;
import std.range;

void main()
{
     string[string] aa;

     // what others have referred to as
     // standard sort works but is deprecated
     //auto keys = aa.keys.sort;

     // Error: cannot infer argument types, expected 1 argument, 
not 2
     import std.algorithm: sort;
     auto keys = aa.keys.sort();

     // this works but why should I have to?
     //import std.array: array;
     //auto keys = aa.keys.sort().array;

     foreach (i, v; keys){}
}

If I hand you a chihuahua for grooming, why am I getting back a 
pit bull? I simply want a groomed chihuahua. Why do I need to 
consult a wizard to get back a groomed chihuahua?


More information about the Digitalmars-d-learn mailing list