Is it possible to override and overload class Object?

Salih Dincer salihdb at hotmail.com
Tue Sep 19 13:35:27 UTC 2023


On Tuesday, 19 September 2023 at 06:28:07 UTC, JG wrote:
> It is a bit unclear, what you want to achieve. Forgetting about 
> the implementation what would you like to write but can't?

Actually, what I want to do is quite simple: The data kept as AA 
will be stored in a payload array and according to its value.  
But it's not enough!  Because whenever I want, I have to add 
string to key(id) or change the value mathematically.  I managed 
to do this, but it was a very winding road :(

For example:

```d
string[size_t] data;

void main()
{
   data = [0: "zero", 1: "one",  2: "two", 3: "three",
           4: "four", 5: "five", 6: "six"];

   auto len = data.length;
   auto arr = new Type[len];

   foreach(i, ref e; arr)
   {
     e = Type(data[i], cast(int)i);
   }

   auto pay = Array!Type(arr.ptr, len);
   pay[] ~= " quantity";
   pay[] += 10;
   pay.writeln; /* Prints:
     [zero quantity: 10, one quantity: 11,
       two quantity: 12, three quantity: 13,
      four quantity: 14, five quantity: 15,
       six quantity: 16] //*/
}
```

SDB at 79


More information about the Digitalmars-d mailing list