Skip to content

Commit

Permalink
Merge pull request #1180 from markisaa/issue_15471
Browse files Browse the repository at this point in the history
Issue 15471: Associative Arrays: add example of static initialization
  • Loading branch information
andralex committed Jan 5, 2016
2 parents 3369f3a + b167fd1 commit 6eed593
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions spec/hash-map.dd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(SPEC_S Associative Arrays,
$(P $(BLUE $(B Note:)) The built-in associative arrays do not preserve the order
of the keys inserted into the array. In particular, in a $(D foreach) loop the
order in which the elements are iterated is unspecified.)

$(H3 Removing Keys)

$(P Particular keys in an associative array can be removed with the
Expand All @@ -46,7 +46,7 @@ $(H3 Testing Membership)

---------
int* p;

p = ("hello" $(CODE_HIGHLIGHT in) aa);
if (p !is null)
{
Expand Down Expand Up @@ -236,6 +236,23 @@ $(H3 Construction or Assignment on Setting AA Entries)
---------
)

$(H3 Static Initialization of AAs)

---------
immutable long[string] aa = [
"foo": 5,
"bar": 10,
"baz": 2000
];

unittest
{
assert(aa["foo"] == 5);
assert(aa["bar"] == 10);
assert(aa["baz"] == 2000);
}
---------

$(H3 Runtime Initialization of Immutable AAs)

$(P Immutable associative arrays are often desirable, but sometimes
Expand Down

0 comments on commit 6eed593

Please sign in to comment.