AA default value?

Janice Caron caron800 at googlemail.com
Fri Jan 25 11:11:56 PST 2008


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)?



More information about the Digitalmars-d mailing list