.sort vs sort(): std.algorithm not up to the task?
Seb via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 7 19:43:03 PDT 2017
On Thursday, 8 June 2017 at 01:57:47 UTC, Andrew Edwards wrote:
> 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?
> ...
> 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?
A magician should never reveal his secrets, but this I do share.
.sort() returns a SortedRange [1] that encapsulates the range.
The trick is to use .release() to release the controlled range
and return it, e.g.
import std.algorithm : sort;
auto keys = aa.keys.sort().release;
[1] https://dlang.org/phobos/std_range.html#SortedRange
More information about the Digitalmars-d-learn
mailing list