www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - arrays with non-int indexes

reply "Bent Rasmussen" <exo bent-rasmussen.info> writes:
I didn't dare hope that this would compile

class A
{
 float opIndex(float k) {
  return k;
 }
 float opIndex(float k, float v) {
  return k;
 }
}

I have to say that this is cool! If at some point in the future I can also
do e.g.

class A
{
 float opIndex(float k1, float k2, float k3) {
  ...
 }
 float opIndex(float k1, float k2, float k3, float v) {
  ...
 }
 ...
}

That'll be awesome! Not to speak of slicing...
Jun 15 2004
parent Norbert Nemec <Norbert.Nemec gmx.de> writes:
Bent Rasmussen wrote:

 I didn't dare hope that this would compile
 
 class A
 {
  float opIndex(float k) {
   return k;
  }
  float opIndex(float k, float v) {
   return k;
  }
 }
Actually, after the recent introduction of opIndexAssign, this will have to be: class A { float opIndex(float k) { return k; } float opIndexAssign(float v, float k) { return k; } } (Not sure about the final resolution about the ordering of the arguments.)
Jun 16 2004