add section about associative arrays

This commit is contained in:
Johannes Loher 2018-04-13 18:08:02 +02:00
parent d15f34a530
commit bcb11b736b

View file

@ -56,8 +56,8 @@ brew cask install visual-studio-code
* Open the Extension view in the sidebar:
|Operating system|Shortcut |
|----------------|---------|
|OS X |⌘ + ⇧ + X|
|Windows |⌃ + ⇧ + X|
|OS X|⌘ + ⇧ + X|
|Windows|⌃ + ⇧ + X|
* Install the extension “D Programming Language (code-d)” (requires that git is
installed).
* Restart Visual Studio Code.
@ -721,3 +721,17 @@ Slices are the most prominent example of `RandomAccessRange`s in
The D standard library provides a huge arsenal of lazy range algorithm
functions. Most of them can be found in in the `std.range` and `std.algorithm`
packages.
### Associative arrays
D has builtin hashmaps, which are called _associative arrays_:
```D
int[string] map; // keys of type string, values of type int
map["key1"] = 10; // insertion or modification, if the key already exists
if ("key1" in map) { // checking if a key is in an associative array
writeln("key1 is in map");
}
assert(map.length == 1); // associative arrays provide a .length property
map.remove("key1"); // remove a key from an associative array
```