Enumap

A structure that maps each member of an enum to a single value.

An Enumap is a lightweight alternative to an associative array that is useable when your key type is an enum.

It provides some added benefits over the AA, such as array-wise operations, default values for all keys, and some nice opDispatch based syntactic sugar for element access.

The key enum must be backed by an integral type and have 'default' numbering. The backing value must start at 0 and grows by 1 for each member.

Constructors

this
this(V[length] values)

Construct an Enumap from a static array.

this
this(R values)

Assign from a range with a number of elements exactly matching length.

Members

Functions

byKey
auto byKey()

Get a range iterating over the members of the enum K.

byKeyValue
auto byKeyValue()

Return a range of (EnumMember, value) pairs.

byValue
auto byValue()

Get a range iterating over the stored values.

opApply
int opApply(int delegate(K, const V) dg)

Execute a foreach statement over (EnumMember, value) pairs.

opApply
int opApply(int delegate(K, ref V) dg)

Execute foreach over (EnumMember, ref value) pairs to modify elements.

opAssign
void opAssign(T val)

An Enumap can be assigned from an array or range of values

opBinary
auto opBinary(typeof(this) other)

Apply an array-wise operation between two Enumaps.

opDispatch
auto ref opDispatch()

Access the value at the index specified by the name of an enum member.

opIndex
auto ref opIndex(K key)

Access the value at the index specified by an enum member.

opOpAssign
auto opOpAssign(typeof(this) other)

Perform an in-place operation.

opUnary
auto opUnary()

Perform a unary operation on each entry.

Static variables

length
auto length;

The number of entries in the Enumap

Parameters

K

The type of enum used as a key. The enum values must start at 0, and increase by 1 for each entry.

V

The type of value stored for each enum member

Meta