Template Enumap.opBinary
Apply an array-wise operation between two
s.
Enumap
Arguments
template opBinary(string op);
Functions
Function name | Description |
---|---|
opBinary |
Example
immutable base = enumap(Element.water, 4, Element.air , 3); immutable bonus = enumap(Element.water, 5, Element.fire, 2); immutable sum = base + bonus; immutable diff = base - bonus; immutable prod = base * bonus; assert(sum.water == 4 + 5); assert(sum.air == 3 + 0); assert(sum.fire == 0 + 2); assert(sum.earth == 0 + 0); assert(diff.water == 4 - 5); assert(diff.air == 3 - 0); assert(diff.fire == 0 - 2); assert(diff.earth == 0 - 0); assert(prod.water == 4 * 5); assert(prod.air == 3 * 0); assert(prod.fire == 0 * 2); assert(prod.earth == 0 * 0);
Example
auto inventory = enumap( ItemType.junk , [ "Gemstone" ], ItemType.normal, [ "Sword", "Shield" ], ItemType.key , [ "Bronze Key" ]); auto loot = enumap( ItemType.junk , [ "Potato" ], ItemType.normal, [ "Potion" ], ItemType.key , [ "Skeleton Key" ]); inventory ~= loot; assert(inventory.junk == [ "Gemstone", "Potato" ]); assert(inventory.normal == [ "Sword", "Shield" , "Potion" ]); assert(inventory.key == [ "Bronze Key" , "Skeleton Key" ]);
Authors
Ryan Roden-Corrent (rcorre)
Copyright
© 2015, Ryan Roden-Corrent
License
MIT