mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added std::collections::enummap.
This commit is contained in:
committed by
Christoffer Lerno
parent
1035de3b36
commit
549e1b6029
18
lib/std/collections/enummap.c3
Normal file
18
lib/std/collections/enummap.c3
Normal file
@@ -0,0 +1,18 @@
|
||||
module std::collections::enummap<Enum, ValueType>;
|
||||
|
||||
struct EnumMap
|
||||
{
|
||||
ValueType[Enum.len] values;
|
||||
}
|
||||
|
||||
fn void EnumMap.init(EnumMap* this, ValueType init_value)
|
||||
{
|
||||
foreach(&a : this.values)
|
||||
{
|
||||
*a = init_value;
|
||||
}
|
||||
}
|
||||
|
||||
fn uint EnumMap.len(EnumMap* this) @operator(len) => this.values.len;
|
||||
fn ValueType EnumMap.get(EnumMap* this, Enum key) @operator([]) => this.values[key.ordinal];
|
||||
fn void EnumMap.set(EnumMap* this, Enum key, ValueType value) @operator([]=) => this.values[key.ordinal] = value;
|
||||
Reference in New Issue
Block a user