Wrong lowering for a[b][c]++

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Mar 21 11:53:24 PDT 2012


On Wed, Mar 21, 2012 at 02:39:04PM -0400, Jonathan M Davis wrote:
[...]
> IMHO, it's _horrible_ that C++ creates entries in a std::map when you
> ask for values that aren't there. A RangeError is _exactly_ what
> should be happening here. There's no element to increment, because it
> hasn't been added yet. I think that the current behavior is very much
> what the behavior _should_ be.
[...]

Then what about:

	int[string][int] map;
	map["abc"][30] = 123;

?

Here, you clearly intend to create a new entry, but currently this
doesn't work. It will throw a RangeError when it tries to look up "abc".
You need the ugly workaround:

	int[string][int] map;
	map["abc"] = int[int].init;
	map["abc"][30] = 123;


T

-- 
What doesn't kill me makes me stranger.


More information about the Digitalmars-d mailing list