Bug 8343 – Last argument of topNCopy forcing a sort?

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-03T13:21:08Z
Last change time
2017-08-17T11:48:18Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-07-03T13:21:08Z
See also Issue 8342 Currently I think topNCopy gives a heap instead of a sorted output when you give it a range that can't be sorted. In this case the last argument of topNCopy must be false (that is the default). But if the programmer gives "true" as the last argument, can't topNCopy just sort the little result calling sort() on it before returning? This way you don't have to call sort() yourself on the result if you need it truly sorted. (Please close this enhancement request if I am missing something.)
Comment #1 by razvan.nitu1305 — 2017-08-17T11:47:42Z
From docs : "If sorted is true, the target is sorted. Otherwise, the target respects the heap property" [1]. [1] https://dlang.org/phobos/std_algorithm_sorting.html#topNCopy > But if the programmer gives "true" as the last argument, can't topNCopy just sort the little result calling sort() on it before returning? That is exactly what it does. Closing as invalid.