Lets a table be used in a for loop: it is the value and it_index the key.
for *table gives a pointer to the value to change it in place, and for < goes in reverse slot order.
Inside the body remove it; deletes the current entry (it leaves a marker, as table_remove does). Entries
come in slot order, not in the order they were added in. Do not add to the table in the body, since growth
moves the entries mid-loop.
table: Table(int, int);
for 0..9 table_add(*table, it, it * it);
for *square, key: table square.* += key; // in place
for square, key: table {
if key % 2 == 0 remove square;
}
assert(table.count == 5);
deinit(*table);for_expansion :: (table: *$T/Table, body: Code, flags: For_Flags)
Lets a table be used in a for loop: it is the value and it_index the key.
for *table gives a pointer to the value to change it in place, and for < goes in reverse slot order.
Inside the body remove it; deletes the current entry (it leaves a marker, as table_remove does). Entries
come in slot order, not in the order they were added in. Do not add to the table in the body, since growth
moves the entries mid-loop.
Parameters
- table: *$T/Table
- body: Code
- flags: For_Flags
table: Table(int, int);
for 0..9 table_add(*table, it, it * it);
for *square, key: table square.* += key; // in place
for square, key: table {
if key % 2 == 0 remove square;
}
assert(table.count == 5);
deinit(*table);