The Anh Tran wrote: > Hi, > > When porting from c++ to D, i encounter this strange discrimination: > 1. Built-in AA: > int[int] arr; > arr[123] += 12345; > arr[321]++; > > 2. Tango HashMap: > auto hm = new HashMap!(int, int)(); > hm[123] += 12345; // error not lvalue > hm[123]++; // error > > D document says current opIndexAssign does not work as lvalue. But why > can builtin AA can that? How can i copy builtin AA behaviour? >
Take a look at tools.behave_as (for phobos). It only works properly with built-in types though. http://dsource.org/projects/scrapple/browser/trunk/tools/tools/behave_as.d It should let you implement a HashMap that supports += and similar, at least for built-ins.