Bug 20932 – Need a stableStaticSort to complement staticSort

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-06-15T15:35:24Z
Last change time
2024-12-01T16:36:59Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: phobos#9797 →

Comments

Comment #0 by andrej.mitrovich — 2020-06-15T15:35:24Z
Consider this simple example: ----- import std.meta; void main () { struct S (size_t idx, string val) { enum index = idx; enum value = val; } enum Comp (T1, T2) = T1.index > T2.index; alias seq = AliasSeq!(S!(0, "a"), S!(0, "b"), S!(1, "c"), S!(1, "d"), S!(2, "e"), S!(2, "f")); alias sorted = staticSort!(Comp, seq); pragma(msg, sorted); } ----- Outputs: (S!(2u, "e"), S!(2u, "f"), S!(1u, "d"), S!(1u, "c"), S!(0u, "b"), S!(0u, "a")) But this is an unstable sort. It would be great to have a stable version. It's output would be: (S!(2u, "e"), S!(2u, "f"), S!(1u, "c"), S!(1u, "d"), S!(0u, "a"), S!(0u, "b"))
Comment #1 by robert.schadek — 2024-12-01T16:36:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9797 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB