View source code
Display the source code in std/array.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.array.assocArray
Returns a newly allocated associative array from a range of key/value tuples.
auto auto assocArray(Range)
(
Range r
)
if (isInputRange!Range);
Parameters
Name | Description |
---|---|
r | An input range of tuples of keys and values. |
Returns
A newly allocated associative array out of elements of the input range, which must be a range of tuples (Key, Value). Returns a null associative array reference when given an empty range.
Duplicates
Associative arrays have unique keys. If r contains duplicate keys, then the result will contain the value of the last pair for that key in r.
See Also
Tuple
, std
Example
import std .range;
import std .typecons;
auto a = assocArray(zip([0, 1, 2], ["a", "b", "c"])); // aka zipMap
assert(is(typeof(a) == string[int]));
writeln(a); // [0:"a", 1:"b", 2:"c"]
auto b = assocArray([ tuple("foo", "bar"), tuple("baz", "quux") ]);
assert(is(typeof(b) == string[string]));
writeln(b); // ["foo":"bar", "baz":"quux"]
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.