View source code
Display the source code in std/array.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.array.assocArray
Returns a newly allocated associative array from a range of key/value tuples.
Prototype
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).
See Also
Example
import std.range; import std.typecons; auto a = assocArray(zip([0, 1, 2], ["a", "b", "c"])); assert(is(typeof(a) == string[int])); assert(a == [0:"a", 1:"b", 2:"c"]); auto b = assocArray([ tuple("foo", "bar"), tuple("baz", "quux") ]); assert(is(typeof(b) == string[string])); assert(b == ["foo":"bar", "baz":"quux"]);
Authors
Andrei Alexandrescu and Jonathan M Davis