is it possible to define a property to access (read/write) a matrix? (I.e., more dimensions than a vector)

Charles D Hixson charleshixsn at earthlink.net
Thu Jul 27 21:07:08 PDT 2006


Mike Parker wrote:
> Charles D Hixson wrote:
>> If it is possible, then could someone point me to where it's
>> documented?  Or show me an example of how?
>>
>> Thank you.
> 
> Do you mean like this?
> 
> class MyMatrix
> {
>    float opIndex(uint i, uint j)
>    {
>       return values[i][j];
>    }
> 
>    float opIndexAssign(float val, uint i, uint j)
>    {
>       values[i][j] = val;
>    }
> }
> 
> MyMatrix mat = new mat;
> mat[0,0] = 0.0f;
> float f = mat[0,0];
Thank you, yes.

I was certain that wouldn't work, so I was asking about
something else...but if that works it does precisely what I
wanted better than custom properties would.

Although... well, I was asking about something that would
look more like:

class MyMatrix
{
   float at(uint i, uint j)
   {
      return values[i][j];
   }

   float at(float val, uint i, uint j)
   {
      values[i][j] = val;
      return val;  //  Not sure about this line
   }
}

MyMatrix mat = new mat;
mat.at(0,0) = 0.0f;
float f = mat.at(0,0);

where the property is "at".  Knowing this would still be
useful, as I might some time want to access things via more
than one method (imagine I had sorted indexes, and was
retrieving the same thing sometimes by name and sometimes by
date, and occasionally by record number).
Still, if this works for opIndexAssign, it probably works
for all properties.



More information about the Digitalmars-d-learn mailing list