www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [rosettacode] std.container.DList problems

This code used to work in DMD 2.065:
http://rosettacode.org/wiki/Strand_sort#D


import std.stdio, std.container;

DList!T strandSort(T)(DList!T list) {
     static DList!T merge(DList!T left, DList!T right) {
         DList!T result;
         while (!left.empty && !right.empty) {
             if (left.front <= right.front) {
                 result.insertBack(left.front);
                 left.removeFront();
             } else {
                 result.insertBack(right.front);
                 right.removeFront();
             }
         }
         result.insertBack(left[]);
         result.insertBack(right[]);
         return result;
     }

     DList!T result, sorted, leftover;

     while (!list.empty) {
         leftover.clear();
         sorted.clear();
         sorted.insertBack(list.front);
         list.removeFront();
         foreach (item; list) {
             if (sorted.back <= item)
                 sorted.insertBack(item);
             else
             leftover.insertBack(item);
         }
         result = merge(sorted, result);
     list = leftover;
     }

     return result;
}

void main() {
     auto lst = DList!int([-2,0,-2,5,5,3,-1,-3,5,5,0,2,-4,4,2]);
     foreach (e; lst.strandSort)
         write(e, " ");
}



Now it gives a runtime error like 
"phobos\std\container\dlist.d(329): DList.front: List is empty". 
I think the cause is that "list = leftover;" has a different 
semantics. Is this a regression fit for Bugzilla?

Bye,
bearophile
Mar 04 2015