ref keys

Namespace rswhite4 at googlemail.com
Mon Sep 17 06:42:55 PDT 2012


Until now it is possible to have const keys in assocative arrays, 
e.g. Tile[const Vector2s], but it isn't possible to have ref 
keys, e.g. Tile[ref Vector2s].

If I have this code:
[code]
class A { }

A a1 = new A();
int[A] array;
[/code]

I can do:
array[new A()] = 42;
array[a1] = 23;

Both lines are valid.
But if I would access the elements later with their keys, I can't 
because I have not a valid key for the element 42, only for 23.

so my suggestion is: allow ref keys.

int[ref A] array;
array[new A()] = 42; // <-- error, new A() isn't a lvalue
array[a1] = 23; // <-- fine


More information about the Digitalmars-d-learn mailing list