digitalmars.D.bugs - does array.sort work at all for opCmp?
- z gg.com (31/31) Aug 10 2005 dmd 129:
- zwang (2/43) Aug 10 2005
- Niko Korhonen (8/9) Aug 11 2005 ...and I think it should be a compiler warning trying to define only
- z gg.com (1/3) Aug 11 2005 Does D support covariant argument type for class method?
dmd 129: sortbug.exe 1.000000 3.000000 2.000000 2.000000 3.000000 1.000000 sortbug.d ------------------------------------------ class A { public: float value; this(float v) {value=v;} int opCmp(A o) { if (this.value < o.value) return -1; if (this.value > o.value) return 1; return 0; } } int main(char[][] args) { int i; A[3] arr; arr[0] = new A(1.0); arr[1] = new A(3.0); arr[2] = new A(2.0); for (i=0; i<3; i++) { printf("%f ", arr[i].value); } printf("\n"); arr.sort; for (i=0; i<3; i++) { printf("%f ", arr[i].value); } printf("\n"); return 0; } ------------------------------------------
Aug 10 2005
You need to define int opCmp(Object o){ ... } z gg.com wrote:dmd 129: sortbug.exe 1.000000 3.000000 2.000000 2.000000 3.000000 1.000000 sortbug.d ------------------------------------------ class A { public: float value; this(float v) {value=v;} int opCmp(A o) { if (this.value < o.value) return -1; if (this.value > o.value) return 1; return 0; } } int main(char[][] args) { int i; A[3] arr; arr[0] = new A(1.0); arr[1] = new A(3.0); arr[2] = new A(2.0); for (i=0; i<3; i++) { printf("%f ", arr[i].value); } printf("\n"); arr.sort; for (i=0; i<3; i++) { printf("%f ", arr[i].value); } printf("\n"); return 0; } ------------------------------------------
Aug 10 2005
zwang wrote:You need to define int opCmp(Object o){ ... }...and I think it should be a compiler warning trying to define only opCmp(MyObj) without defining opCmp(Object) for objects. It would save us from so much hassle. The same thing for not defining toHash when defininng opEquals and so forth. -- Niko Korhonen SW Developer
Aug 11 2005
zwang wrote:Does D support covariant argument type for class method?You need to define int opCmp(Object o){ ... }
Aug 11 2005