[Issue 9887] New: std.array.insertOrdered?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 5 16:19:30 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9887

           Summary: std.array.insertOrdered?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-04-05 16:19:24 PDT ---
This is a way to insert an item in a sorted array:


import std.stdio: writeln;
import std.range: assumeSorted;
import std.array: insertInPlace;
void main() {
    int[] arr = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90];
    int x = 35;
    arr.insertInPlace(arr.assumeSorted.lowerBound(x).length, x);
    arr.writeln;
}


Haskell has the insert/insertBy functions (for lists):
http://zvon.org/other/haskell/Outputlist/insertBy_f.html  
http://zvon.org/other/haskell/Outputlist/insert_f.html

It's an operation not too much rare, and implementing it correctly like I have
shown is not immediate, there is a little risk of introducing a bug. So is it
worth adding such small function std.array.insertOrdered() to std.array?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list