Enumap.opApply - multiple declarations
- Function Enumap.opApply
- Function Enumap.opApply
Function Enumap.opApply
Execute a foreach statement over (EnumMember, value) pairs.
Prototype
int opApply( scope int delegate(K, const V) dg ) const;
Example
foreach iterates over (EnumMember, value) pairs.
const auto elements = enumap(Element.water, 4, Element.air, 3); foreach(key, value ; elements) { assert( key == Element.water && value == 4 || key == Element.air && value == 3 || value == 0); }
Function Enumap.opApply
Execute foreach over (EnumMember, ref value) pairs to modify elements.
Prototype
int opApply( scope int delegate(K, ref V) dg );
Example
foreach can modify values by ref
Enumap!(Element, int) elements; foreach(key, ref value ; elements) { if (key == Element.air) value = 4; else if (key == Element.water) value = 2; } assert(elements.air == 4); assert(elements.water == 2);
Authors
Ryan Roden-Corrent (rcorre)
Copyright
© 2015, Ryan Roden-Corrent
License
MIT