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

1 alias map = KeyValueList!("a", 42, "b", 23);
2 static assert(map.get!"a" == 42);
3 static assert(map.get!("a", "b") == ExpressionList!(42, 23));
4 static assert(map.get!"c".length == 0);
5 
6 alias map2 = KeyValueList!(int, float, float, double, double, 42);
7 static assert(is(map2.get!int == float));
8 static assert(is(map2.get!float == double));
9 static assert(map2.get!double == 42); 
10 
11 static assert(map.has!"a");
12 static assert(map2.has!int);
13 static assert(!map2.has!void);
14 static assert(!map.has!"c");
15 
16 alias map3 = map.set!("c", 4);
17 static assert(map3.get!"c" == 4);
18 alias map4 = map.set!("c", 4, "d", 8);
19 static assert(map4.get!("c", "d") == ExpressionList!(4, 8));
20 alias map5 = map.set!("a", 4);
21 static assert(map5.get!"a" == 4);
22 
23 template inc(string key, int val)
24 {
25     alias inc = ExpressionList!(key, val+1);
26 }
27 
28 alias map6 = map.map!inc;
29 static assert(map6.get!"a" == 43);
30 static assert(map6.get!("a", "b") == ExpressionList!(43, 24));
31 
32 static assert(map.keys == ExpressionList!("a", "b"));
33 static assert(map.values == ExpressionList!(42, 23));

Meta