alias this and associative arrays
Steven Schveighoffer
schveiguy at yahoo.com
Sun Apr 22 11:30:04 UTC 2018
On 4/22/18 7:06 AM, Shachar Shemesh wrote:
> import std.exception;
>
> struct AA(Key, Val) {
> Val[Key] aa;
> alias aa this;
>
> void opIndexAssign(inout Val value, Key key) pure {
> aa[key] = value;
> }
> }
>
> void main() {
> AA!(string, int) a;
> //compile error -- no property 'remove' for type
> 'CheckedAA!(string, int)'
> a.remove("aaa");
> }
>
> What's wrong here?
It's a bug. The remove function is not actually defined by the library,
it's a compiler special that remaps to an extern(C) function _aaDelX. As
far as I can tell, it's the only one that doesn't work. All the others
seem to work (e.g. a.keys).
What I would guess is happening is the compiler is trying to call remove
on the AA but has skipped the part that translates to _aaDelX.
It would be good to hoist this out of the compiler and make it a UFCS
call, which would also fix the problem.
-Steve
More information about the Digitalmars-d
mailing list