AA default value?

Jason House jason.james.house at gmail.com
Fri Jan 25 10:58:32 PST 2008


Sean Kelly Wrote:

> Oskar Linde wrote:
> > I believe the implemented solution to the old problem overshoot the best
> > solution, which would have been to make a rvalue expression aa[5] return
> > 0, but *without* inserting 5 into the aa.
> 
> Agreed.  And I think this was brought up at the time, but it wasn't
> implemented for some reason.

That solution is assuming a specific answer to the question of "should indexing a non-existent entry be an error?".  Sometimes, I write code that assumes stuff will be pre-existing in an AA / STL map.  When this is the case, I prefer the D behavior.  When code works better with defaults, it's annoying.  I'd really prefer to have a choice.

Additionally, AA's of classes that return null for unused indexes isn't particularly helpful.  Returning a non-duped default object is usually worse than returning null.  To me, there seems to be enough variation in what people would want that some kind of policy (template paramter, included function object, etc...) would be better.



More information about the Digitalmars-d mailing list