"Overlapping array copy" exception sorting an array of Tuples

André Stein stone at steinsoft.net
Mon Mar 7 06:36:31 PST 2011


Hi,

I'm trying to sort an array of tuples (Tuple!(uint, string) type) but the
program bails out with the exception "overlapping array copy"
(arraycat.d(40)). To make things short here is the source code:

import std.typecons;
import std.algorithm;
void main(string[] args)
{
    alias Tuple!(uint, "number", string, "text") TestT;
    TestT[] array = [ TestT(50, "test1"), TestT(100, "test2"), TestT(68,
"test3") ];
    sort(array);
}

When I implement a struct TestT which imitates the behaviour of the concrete
Tuple-type the sorting algorithm just works fine:

struct TestT
{
    uint number; string text;

    this(uint number, string text)
    {
        this.number = number;
        this.text = text;
    }

    int opCmp(TestT rhs)
    {
        return number - rhs.number;
    }
}

void main(string[] args)
{
     TestT[] array = [ TestT(50, "test1"), TestT(100, "test2"), TestT(68,
"test3") ];
    sort(array);
}

I don't really understand this error. Am I missing something in the usage of
Tuple? Or might this be a bug in the sort implementation? Btw. I am using the
latest version of the DMD compiler. Compiling and running the source with the
"-release" flag doesn't end with an exception and seems to produce the right
sorted array.

Thanks in advance for any clarifications!

Regards,
André


More information about the Digitalmars-d-learn mailing list