Feature to get or add value to an associative array.

MrSmith mrsmith33 at yandex.ru
Tue Apr 17 19:33:16 UTC 2018


On Tuesday, 17 April 2018 at 17:27:02 UTC, Giles Bathgate wrote:
> I like the name. I think your version is quite low level which 
> ultimately provides more power at the expense of making the 
> callee code less clean. I am not sure with D which of those two 
> aspects is preferred. Perhaps both functions could be provided? 
> What is the use case for knowing whether a value was inserted.

You may need to perform extra logic when value is inserted in the 
container and something else when value already existed.

I have a special version of function for that:
Value* getOrCreate(Key key, out bool wasCreated, Value 
default_value = Value.init)

here is an example of usage: 
https://github.com/MrSmith33/voxelman/blob/master/plugins/voxelman/entity/entityobservermanager.d#L33


More information about the Digitalmars-d mailing list