An error on trying to sort shared data using slice

bearophile bearophileHUGS at lycos.com
Mon Jan 28 06:30:25 PST 2013


Sparsh Mittal:

It compiles if you remove the shared:


import std.stdio: sort;

struct Intpair {
     int[2] allInts;
}

/*shared*/ Intpair[] distArray;

void main() {
     enum numberOfLines = 10;
     distArray.length = numberOfLines;

     static bool myComp(in /*shared*/ Intpair x,
                        in /*shared*/ Intpair y) {
         return x.allInts[0] < y.allInts[0];
     }

     enum startRange = 1;
     enum endRange = 3;
     /*shared*/ auto tempSortArray =
         distArray[startRange .. endRange + 1];
     sort!myComp(tempSortArray);
}


Also, take a look a the common D style:
http://dlang.org/dstyle.html

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list