Skip to content
MapGetOrDefault

MapGetOrDefault

MapGetOrDefault

Description

Get the first value stored for a key, or return a fallback value copy.

This returns a value copy, not a pointer. The fallback value is not inserted into the map. If you want insertion-on-miss semantics, use MapGetOrInsertPtr.

Parameters

Name Direction Description
m in,out Map.
lookup_key in Key to search for.
default_value in Value returned when key does not exist.

Success

First stored value for key, or default_value when absent.

Failure

Does not return on invalid arguments.

Usage example (Cross-references)

Usage examples (Cross-references)
        MapInsertR(&map, 11, 111);
    
        int  found  = MapGetOrDefault(&map, 11, 999);
        int  miss   = MapGetOrDefault(&map, 999, 555);
        bool result = (found == 110);
    
        int  found  = MapGetOrDefault(&map, 11, 999);
        int  miss   = MapGetOrDefault(&map, 999, 555);
        bool result = (found == 110);
        result      = result && (miss == 555);
Last updated on