AA default value?

Jason House jason.james.house at gmail.com
Fri Jan 25 12:08:16 PST 2008


Janice Caron Wrote:

> On 1/25/08, Jason House <jason.james.house at gmail.com> wrote:
> > I'd really prefer to have a choice.
> 
> Yeah! I'll second that.
> 
> Not sure how it would work though. Maybe something like:
> 
>     int[int] aa;
>     auto x = aa[5]; // run-time error
> 
>     aa.default = 0;
>     auto y = aa[5]; // y = 0;
> 
> > 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.
> 
> Sounds good to me. Maybe the .default property could be lazy (so it
> could call new when needed)?

I'd be content with (lazy) syntax above.  Two gotchas:
* The default keyword (used in switches) may block that property
* New AA's are null and property access would fail.  Of course, I'd like to see that changed anyway.



More information about the Digitalmars-d mailing list