Hash

A templated datatype which stores key => value pairs. Keys and values stored in hash need not be unique.

Querying hashes can be done with both compile-time and run-time values.

Hash!(a => 1) hash;

assert(hash["a"] == Variant(1));
assert(hash.value!"a" == 1);

Hashes also allow for duplicate keys, and value selection by type.

int xInt;
string xString;
Hash!(x => 5, x => "10") hash;

hash.get("x", xInt);    // Or xInt    = hash.value!("x", int);
hash.get("x", xString); // Or xString = hash.value!("x", string);

assert(xInt == 5);
assert(xString == "10");

Members

Properties

value
auto value [@property getter]

Returns a value from the hash by name.

values
T[] values [@property getter]

Returns all values in the hash converted to a type given by T.

Static functions

apply
T apply(T dest)

Applies the hash onto a value which is a class or struct given by T.

concat
auto concat(Hash!other )

Concatenates two hashes. Duplicate keys and values are preserved.

get
bool get(string name, T dest)

Fetches an element by its runtime name and stores it into the destination parameter.

hasKey
bool hasKey(string name)

Checks for the presence of a key in the hash.

opApply
int opApply(int delegate(Variant) dg)

Iterates over the values in the hash as Variants.

opApply
int opApply(int delegate(string, Variant) dg)

Ditto, but also iterates over keys.

opBinary
auto opBinary(Hash!other o)

Concatenates two hashes. Duplicate keys and values are preserved.

opIndex
Variant opIndex(string name)

Fetches a value from the hash as a Variant.

Variables

empty
enum bool empty;

Tests for an empty hash.

hasKey
enum bool hasKey(string name);

Ditto, but accepts a template parameter.

keys
enum string[] keys;

Unique set of key names in the hash. The order of keys is unspecified.

length
enum size_t length;

Returns the number of values in the hash.

Meta