Skip to content
MapForeachPair

MapForeachPair

Description

Iterate over all stored key/value pairs by value.

Parameters

Name Direction Description
m in,out Map to iterate over.
key_var in Name of variable bound to a copy of each pair’s key.
value_var in Name of variable bound to a copy of each pair’s value.

Success

The loop body runs once per occupied slot with key_var and value_var bound to copies of the stored key and value. The body is skipped when m is empty. Mutating the locals does not write back into the map.

Failure

The macro itself does not fail. LOG_FATAL via ValidateMap(m) when m is uninitialised or corrupted.

Usage example (Cross-references)

Usage examples (Cross-references)
        MapInsertR(&map, 2, 25);
    
        MapForeachPair(&map, key, value) {
            key_sum   += key;
            value_sum += value;
        int key_sum_again   = 0;
        int value_sum_again = 0;
        MapForeachPair(&map, key, value) {
            key_sum_again   += key;
            value_sum_again += value;
            n += 1;
        }
        MapForeachPair(&map, k, v) {
            (void)k;
            (void)v;
Last updated on