digitalmars.D - Extra Array Operator Overloading Request
- Jonathan Crapuchettes (3/3) May 30 2007 I do a lot of matrix calculations with a D library that I have written a...
- Johan Granberg (3/7) May 30 2007 What is preventing you from doing so now? if opIndex returns a type that
- Frits van Bommel (5/14) May 30 2007 Typically, if you have a matrix of T you'd want to have mat[i,j] (or
- Johan Granberg (3/19) May 30 2007 But if T supports both opIndex and opAssign that wouldn't be a problem,
- Frits van Bommel (10/29) May 30 2007 (Presumably you mean opAddAssign instead of opIndex?)
I do a lot of matrix calculations with a D library that I have written and it would be really nice to be able to overload a few more array operators, like assigned multiplication (i.e. mat1[i,j] += mat2[i,j];). Has this feature been approved, discussed, or planned? Thanks, JC
May 30 2007
Jonathan Crapuchettes wrote:I do a lot of matrix calculations with a D library that I have written and it would be really nice to be able to overload a few more array operators, like assigned multiplication (i.e. mat1[i,j] += mat2[i,j];). Has this feature been approved, discussed, or planned? Thanks, JCWhat is preventing you from doing so now? if opIndex returns a type that overloads opAddAssign your example should be possible right now.
May 30 2007
Johan Granberg wrote:Jonathan Crapuchettes wrote:Typically, if you have a matrix of T you'd want to have mat[i,j] (or mat[i][j]) return either a T or something that implicitly converts to one. Since you can only overload operators on aggregates (class, struct, union) but can't define implicit conversions for them...I do a lot of matrix calculations with a D library that I have written and it would be really nice to be able to overload a few more array operators, like assigned multiplication (i.e. mat1[i,j] += mat2[i,j];). Has this feature been approved, discussed, or planned? Thanks, JCWhat is preventing you from doing so now? if opIndex returns a type that overloads opAddAssign your example should be possible right now.
May 30 2007
Frits van Bommel wrote:Johan Granberg wrote:But if T supports both opIndex and opAssign that wouldn't be a problem, right?Jonathan Crapuchettes wrote:Typically, if you have a matrix of T you'd want to have mat[i,j] (or mat[i][j]) return either a T or something that implicitly converts to one. Since you can only overload operators on aggregates (class, struct, union) but can't define implicit conversions for them...I do a lot of matrix calculations with a D library that I have written and it would be really nice to be able to overload a few more array operators, like assigned multiplication (i.e. mat1[i,j] += mat2[i,j];). Has this feature been approved, discussed, or planned? Thanks, JCWhat is preventing you from doing so now? if opIndex returns a type that overloads opAddAssign your example should be possible right now.
May 30 2007
Johan Granberg wrote:Frits van Bommel wrote:(Presumably you mean opAddAssign instead of opIndex?) Only if T is a struct or union[1], and its author was aware of the need to put it in that particular Matrix implementation (or you're willing to modify it to fit[2]). If it's a primitive type like (int, float, cfloat) and variants, or a class (hint: opAssign can't modify the reference) you're screwed. [1]: Requirements: value type with possibility of operator overloading. [2]: Hopefully by way of a mixin, since there's a lot of op<X>Assign operators.Johan Granberg wrote:But if T supports both opIndex and opAssign that wouldn't be a problem, right?Jonathan Crapuchettes wrote:Typically, if you have a matrix of T you'd want to have mat[i,j] (or mat[i][j]) return either a T or something that implicitly converts to one. Since you can only overload operators on aggregates (class, struct, union) but can't define implicit conversions for them...I do a lot of matrix calculations with a D library that I have written and it would be really nice to be able to overload a few more array operators, like assigned multiplication (i.e. mat1[i,j] += mat2[i,j];). Has this feature been approved, discussed, or planned? Thanks, JCWhat is preventing you from doing so now? if opIndex returns a type that overloads opAddAssign your example should be possible right now.
May 30 2007