|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
digitalmars.D.dtl - AA indexing behavior
As an experiment I've changed the MinTL AA indexing behavior for HashAA and SortedAA to give more flexibility: 1) opIndex returns a settable missing value (the property is called 'missing'). The default missing value is Value.init. The Value take(Key) function also returns the default missing value on failure. 2) added bool contains(Key key) and bool contains(Key key, out Value value) 3) added Value* get(Key key, int action = NullOnMiss) where action can be one of the three predefined enum values NullOnMiss, ThrowOnMiss and InsertOnMiss So the old opIn (equivalent to the builtin 'in') is now get(key). Most of the time, though, the indexing or contains functions will do. For instance names[phone] = a_name; Times when a get() is needed would be for fancy things like (*count.get(word,InsertOnMiss))++ which is how one can mimic the builtin lvalue indexing behavior. One interesting question is if the get(word,InsertOnMiss) should insert the missing value or Value.init. Right now I have it inserting Value.init. Anyhow, comments welcome. -Ben Jul 27 2005
3) added Value* get(Key key, int action = NullOnMiss) where action can be one of the three predefined enum values NullOnMiss, ThrowOnMiss and InsertOnMiss Jul 28 2005
|