Infinite loop using phobos sort
Nick Voronin
elfy.nv at gmail.com
Wed Dec 15 17:15:43 PST 2010
On Thu, 16 Dec 2010 03:11:40 +0300, Craig Black <craigblack2 at cox.net>
wrote:
> When I try to use Phobos to sort my custom Array, it goes into an
> infinite loop. I suspect I did something wrong with my Range struct.
> Does anyone see an obvious flaw here?
bordercase
> this(ref Array!T array)
> {
> if(array.empty()) return;
> start = &array.front();
> end = &array.back();
end points to last actual element
> }
> this(T *_start, T *_end)
> {
> start = _start;
> end = _end;
same
> }
> Range opSlice(int a, int b) { return Range(start+a, start+b); }
in opSlice second index points _after_ last element you want. a[0..1] --
range of length 1. You need to fix b by -1.
I wonder what kind of assert would catch this one...
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list