Skip to content
MapValueCursorIsValid

MapValueCursorIsValid

Description

Check whether a cursor still points to a value for its key (i.e. the per-key iteration has not yet been exhausted).

Parameters

Name Direction Description
cursor in Cursor returned by MapFindFirstForKey or MapFindNextForKey.

Success

Returns true when cursor refers to an in-range entry (i.e. it is not the past-the-end sentinel). No map is touched.

Failure

Returns false when cursor equals MapValueCursorInvalid(), meaning the per-key iteration is done. No map is touched.

Usage example (Cross-references)

Usage examples (Cross-references)
    
        MapValueCursor cursor = MapFindFirstForKey(&map, 15);
        bool           ok     = MapValueCursorIsValid(cursor);
    
        MapRemoveFirst(&map, 10);
        // Cursor APIs on an empty map are invalid / NULL.
        MapValueCursor cursor = MapFindFirstForKey(&map, 7);
        result                = result && !MapValueCursorIsValid(cursor);
        result                = result && (MapValuePtrFromCursor(&map, cursor) == NULL);
    
        cursor = MapFindFirstForKey(&map, 4);
        while (MapValueCursorIsValid(cursor)) {
            int *value_ptr = MapValuePtrFromCursor(&map, cursor);
            if (!value_ptr) {
    
        bool result = (seen == 3) && (value_sum == (40 + 41 + 42));
        result      = result && !MapValueCursorIsValid(MapFindFirstForKey(&map, 99));
        result      = result && (MapValuePtrFromCursor(&map, MapValueCursorInvalid()) == NULL);
    
        // Loop terminated because the cursor went invalid past the last value.
        result = result && !MapValueCursorIsValid(cursor);
    
        // Single-valued key: first is valid, next past the end stays invalid,
        // and advancing an already-invalid cursor remains invalid.
        MapValueCursor single = MapFindFirstForKey(&map, 9);
        result                = result && MapValueCursorIsValid(single);
        MapValueCursor past   = MapFindNextForKey(&map, 9, single);
        result                = result && !MapValueCursorIsValid(past);
        result                = result && MapValueCursorIsValid(single);
        MapValueCursor past   = MapFindNextForKey(&map, 9, single);
        result                = result && !MapValueCursorIsValid(past);
        result                = result && !MapValueCursorIsValid(MapFindNextForKey(&map, 9, past));
        MapValueCursor past   = MapFindNextForKey(&map, 9, single);
        result                = result && !MapValueCursorIsValid(past);
        result                = result && !MapValueCursorIsValid(MapFindNextForKey(&map, 9, past));
    
        MapDeinit(&map);
    
        cursor = MapFindFirstForKey(&map, 5);
        if (!MapValueCursorIsValid(cursor)) {
            MapDeinit(&map);
            DefaultAllocatorDeinit(&alloc);
Last updated on