KeyValueList

Static associative map.

Pairs is a list of pairs key-value.

Members

Aliases

keys
alias keys = getKeys!Pairs

Getting expression list of all keys

values
alias values = getValues!Pairs

Getting expression list of all values

Manifest constants

length
enum length;

Number of entries in the map

Templates

filter
template filter(alias F)

Filters entries with function or template F, leaving entry only if F returning true.

filterByKey
template filterByKey(alias F)

Filters entries with function or template F passing only a key from an entry, leaving entry only if F returning true.

get
template get(Keys...)

Getting values by keys. If Keys is a one key, then returns unwrapped value, else a ExpressionExpressionList of values.

has
template has(Key...)

Returns true if map has a Key

map
template map(alias F)

Applies F template for each pair (key-value).

set
template set(KeyValues...)

Setting values to specific keys (or adding new key-values)

Examples

alias map = KeyValueList!("a", 42, "b", 23);
static assert(map.get!"a" == 42);
static assert(map.get!("a", "b") == ExpressionList!(42, 23));
static assert(map.get!"c".length == 0);

alias map2 = KeyValueList!(int, float, float, double, double, 42);
static assert(is(map2.get!int == float));
static assert(is(map2.get!float == double));
static assert(map2.get!double == 42); 

static assert(map.has!"a");
static assert(map2.has!int);
static assert(!map2.has!void);
static assert(!map.has!"c");

alias map3 = map.set!("c", 4);
static assert(map3.get!"c" == 4);
alias map4 = map.set!("c", 4, "d", 8);
static assert(map4.get!("c", "d") == ExpressionList!(4, 8));
alias map5 = map.set!("a", 4);
static assert(map5.get!"a" == 4);

template inc(string key, int val)
{
    alias inc = ExpressionList!(key, val+1);
}

alias map6 = map.map!inc;
static assert(map6.get!"a" == 43);
static assert(map6.get!("a", "b") == ExpressionList!(43, 24));

static assert(map.keys == ExpressionList!("a", "b"));
static assert(map.values == ExpressionList!(42, 23));

Meta