www.digitalmars.com         C & C++   DMDScript  
Archives

D Programming
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger
D.gnu
D

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics


digitalmars.D.bugs - bug in std.algoeithm.sort ?

reply A.M. <AMAMH3 Gmail.com> writes:
import std.string;
import std.array;
import std.algorithm;

void main()
{
        string[] sa = ["TOM","JOE","TOM4","TOM12","TOM6"];
        sort!(comp)(sa);
}
bool comp(string x, string y)
{
        string[] s = [x,y];
        return isSorted(s);
}

this code compiles find, but when run gives the following error:

core.exception.AssertError ./../../src/phobos/std/array.d(210): Attempting to
fetch the front of an empty array

same happens if operating on int not string
I'm using dmd2.030
same happens with dmd2.029

is that a bug?
Jun 04 2009
parent Gide Nwawudu <gide btinternet.com> writes:
On Thu, 04 Jun 2009 07:18:33 -0400, A.M. <AMAMH3 Gmail.com> wrote:

import std.string;
import std.array;
import std.algorithm;

void main()
{
        string[] sa = ["TOM","JOE","TOM4","TOM12","TOM6"];
        sort!(comp)(sa);
}
bool comp(string x, string y)
{
        string[] s = [x,y];
        return isSorted(s);
}

this code compiles find, but when run gives the following error:

core.exception.AssertError ./../../src/phobos/std/array.d(210): Attempting to
fetch the front of an empty array

same happens if operating on int not string
I'm using dmd2.030
same happens with dmd2.029

is that a bug?

... Yes, but not with Phobos. The comparison operator should use < less than, if two items are equal they must return false. isSorted(["TOM","TOM"]) is true, "TOM" < "TOM" is false. Gide
Jun 04 2009