Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

This adds a require and update function for Associative Arrays #2162

Merged
merged 10 commits into from
Jun 21, 2018
36 changes: 36 additions & 0 deletions changelog/require_update.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Additional functions for associative arrays

The $(D require) function provides a means to construct a new value when the key
is not present.

---------
class C{}
C[string] aa;

auto a = aa.require("a", new C); // lookup "a", construct if not present
---------

The $(D update) function allows different operations to be performed depending
on whether a value already exists or needs to be constructed.

---------
class C{}
C[string] aa;

C older;
C newer;
aa.update("a",
{
newer = new C;
return newer;
},
(ref C c)
{
older = c;
newer = new C;
return newer;
});
---------

The functions avoid the need to perform multiple key lookups. Further details
are available in the $(LINK2 $(ROOT_DIR)spec/hash-map.html, spec.)
Loading