Skip to content

Vec

Description

Typesafe vector definition. This is much like C++ template std::vector

Using this directly like Vec(T) won’t always work, because each time this is used it defines a new type, and two Vec(T)s are different from each other.

To deal with this, you must typedef vector for a specific type. Throughout the code, any time that is in plural form is generally a vector. Like Strs is a typedef of Vec(Str).

Fields

Name Description
length Number of items currently in vector (always <= capacity)
capacity Max number of items this vector can hold before doing a resize.
copy_init If provided then is used to create owned copies of items into vector.
copy_deinit If provided then is used to deinit data held by vector. Caution when dealing with shared ownership.
data Data held by vector. Don’t access by direct indexing. Use VecAt(..)
allocator Allocator bound to this vector. Its alignment field governs both the alignment of the underlying buffer and the per-element stride. NULL for stack-init vecs (VecInitStack / StrInitStack): the macro plants an _Alignas(T) char[] backing buffer so per-element stride collapses to sizeof(T), and any operation that would grow the vec aborts via VecReserve.

Usage example (from documentation)

  Vec(int) integers; // Vector of integers
  Vec(CustomStruct) my_data; // Vector of CustomStruct
  Vec(float) real_numbers; // Vector of float values
  Vec(Zstr) names; Vector of c-style null-terminated strings

Usage example (Cross-references)

Usage examples (Cross-references)
    
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Container/Str/Private.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Vec/Private.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Types.h>
    // Each `Vec(u64)` use is its own anonymous struct type, so a typedef
    // is required to pass these around between functions.
    typedef Vec(u64) U64Vec;
    
    // ---------------------------------------------------------------------------
    } AbbrevAttr;
    
    typedef Vec(AbbrevAttr) AbbrevAttrVec;
    
    typedef struct AbbrevEntry {
    } AbbrevEntry;
    
    typedef Vec(AbbrevEntry) AbbrevTable;
    
    static void abbrev_table_deinit(AbbrevTable *t) {
    } PendingFn;
    
    typedef Vec(PendingFn) PendingFns;
    
    static bool walk_cu_dies(
    } PendingPub;
    
    typedef Vec(PendingPub) PendingPubs;
    
    static i32 cmp_pending(const void *lhs, const void *rhs) {
    #include "../Harness.h"
    #include "VecCharPtr.h"
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Std/Zstr.h>
    #define FUZZ_VEC_CHAR_PTR_H
    
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Types.h>
    
    // Vec(char*) typedef
    typedef Vec(char *) CharPtrVec;
    
    // Vec(char*) function enumeration
    #define FUZZ_VEC_INT_H
    
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Types.h>
    
    // Vec(i32) typedef
    typedef Vec(i32) IntVec;
    
    // Vec(i32) function enumeration
    #define FUZZ_VEC_STR_H
    
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Allocator/Default.h>
    
    // Vec(Str) typedef
    typedef Vec(Str) StrVec;
    
    // Vec(Str) function enumeration
    #include "../Harness.h"
    #include "VecStr.h"
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Log.h>
    #include "../Harness.h"
    #include "VecInt.h"
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
        f64  small_float;
        bool is_valid;
        Vec(Str) empty_array;
        Vec(i64) numbers;
    } EdgeCaseData;
        bool is_valid;
        Vec(Str) empty_array;
        Vec(i64) numbers;
    } EdgeCaseData;
        StrIter si1   = StrIterFromStr(json1);
    
        Vec(i32) items = VecInit(&alloc);
    
        JR_OBJ(si1, {
        StrIter si2   = StrIterFromStr(json2);
    
        Vec(Str) data = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        JR_OBJ(si2, {
        struct {
            i32 x_value;
            Vec(i32) filled_items;
        } obj = {0, VecInit(&alloc)};
    } AnnSymbol;
    
    typedef Vec(AnnSymbol) AnnSymbols;
    
    typedef struct ApiResponse {
        u64 analysis_id;
        Str sha256;
        Vec(Str) tags;
        Str created_at;
        u64 model_id;
        Str  json    = StrInit(&alloc);
    
        Vec(FunctionInfo) functions = VecInitWithDeepCopy(NULL, FunctionInfoDeinit, &alloc);
    
        FunctionInfo func1 = {12345, StrInitFromZstr("test_func", &alloc), 1024, 4096};
        Str  json    = StrInit(&alloc);
    
        Vec(AnnSymbol) symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc);
    
        AnnSymbol sym1             = {0};
        Str  json    = StrInit(&alloc);
    
        Vec(u32) numbers = VecInit(&alloc);
        u32 num1 = 1, num2 = 2, num3 = 3;
        VecPushBack(&numbers, num1);
        VecPushBack(&numbers, num3);
    
        Vec(Str) strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        // Create strings and push them properly
        VecPushBack(&strings, str3);
    
        Vec(bool) booleans = VecInit(&alloc);
        bool bool1 = true, bool2 = false, bool3 = true;
        VecPushBack(&booleans, bool1);
        Str name;
        f64 price;
        Vec(Str) tags;
    } SimpleProduct;
        Str  json    = StrInit(&alloc);
    
        Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        // Create strings and push them properly
        Str  json    = StrInit(&alloc);
    
        Vec(i32) empty_numbers = VecInit(&alloc);
        Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        Vec(i32) empty_numbers = VecInit(&alloc);
        Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        JW_OBJ(json, {
        Str  json    = StrInit(&alloc);
    
        Vec(i32) empty_list = VecInit(&alloc);
    
        JW_OBJ(json, {
        Str  json    = StrInit(&alloc);
    
        Vec(i32) empty_arr  = VecInit(&alloc);
        Vec(i32) filled_arr = VecInit(&alloc);
        i32 val1 = 1, val2 = 2;
    
        Vec(i32) empty_arr  = VecInit(&alloc);
        Vec(i32) filled_arr = VecInit(&alloc);
        i32 val1 = 1, val2 = 2;
        VecPushBack(&filled_arr, val1);
    } AnnSymbol;
    
    typedef Vec(AnnSymbol) AnnSymbols;
    
    typedef struct ApiResponse {
    } FunctionInfo;
    
    typedef Vec(FunctionInfo) FunctionInfos;
    
    typedef struct ModelInfo {
    } ModelInfo;
    
    typedef Vec(ModelInfo) ModelInfos;
    
    typedef struct SearchResult {
        u64 analysis_id;
        Str sha256;
        Vec(Str) tags;
        Str created_at;
        u64 model_id;
    } SearchResult;
    
    typedef Vec(SearchResult) SearchResults;
    
    void FunctionInfoDeinit(FunctionInfo *info) {
        StrIter si = StrIterFromStr(json);
    
        typedef Vec(AnnSymbol) Symbols;
        Symbols symbols = VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc);
        Str name;
        f64 price;
        Vec(Str) tags;
    } SimpleProduct;
        StrIter si      = StrIterFromStr(json);
    
        Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        JR_OBJ(si, {
        u32  timeout;
        Str  log_level;
        Vec(Str) features;
    } TestConfig;
        TestPerson user;
        TestConfig config;
        Vec(i32) numbers;
        Vec(bool) flags;
    } ComplexData;
        TestConfig config;
        Vec(i32) numbers;
        Vec(bool) flags;
    } ComplexData;
    
        // Original data
        Vec(i32) original_numbers = VecInit(&alloc);
        Vec(Str) original_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        // Original data
        Vec(i32) original_numbers = VecInit(&alloc);
        Vec(Str) original_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        // Populate arrays
    
        // Read back from JSON
        Vec(i32) parsed_numbers = VecInit(&alloc);
        Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        // Read back from JSON
        Vec(i32) parsed_numbers = VecInit(&alloc);
        Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
    
        StrIter si = StrIterFromStr(json);
    
        // Original empty data
        Vec(i32) empty_numbers = VecInit(&alloc);
        Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str empty_str          = StrInit(&alloc);
        // Original empty data
        Vec(i32) empty_numbers = VecInit(&alloc);
        Vec(Str) empty_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str empty_str          = StrInit(&alloc);
    
        // Read back from JSON
        Vec(i32) parsed_numbers = VecInit(&alloc);
        Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str  parsed_str         = StrInit(&alloc);
        // Read back from JSON
        Vec(i32) parsed_numbers = VecInit(&alloc);
        Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
        Str  parsed_str         = StrInit(&alloc);
        bool found_empty_object = false;
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Allocator/Page.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Io.h>
    #include <Misra/Std/Log.h>
        // Exercises the internal descriptor table across multiple grows.
        PageAllocator alloc = PageAllocatorInit();
        typedef Vec(int) IntVec;
        IntVec v  = VecInit(&alloc);
        bool   ok = true;
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Types.h> // For LVAL macro
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    int main(void) {
        alloc = DefaultAllocatorInit();
        WriteFmt("[INFO] Starting Vec.Ops tests\n\n");
    
        // Array of test functions
    
        // Run all tests using the centralized test driver
        int rc = run_test_suite(tests, total_tests, NULL, 0, "Vec.Ops");
        DefaultAllocatorDeinit(&alloc);
        return rc;
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecForeach where modification causes out of bounds access (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecForeachIdx where idx goes out of bounds (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecForeachReverseIdx where idx goes out of bounds (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecForeachPtrIdx where idx goes out of bounds (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecForeachPtrReverseIdx where idx goes out of bounds (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecForeachPtrInRangeIdx where idx goes out of bounds (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing basic VecForeachIdx where idx goes out of bounds (should crash)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    int main(void) {
        alloc = DefaultAllocatorInit();
        WriteFmt("[INFO] Starting Vec.Foreach.Simple tests\n\n");
    
        // Array of normal test functions
    
        // Run all tests using the centralized test driver
        int rc = run_test_suite(tests, total_tests, NULL, 0, "Vec.Foreach.Simple");
        DefaultAllocatorDeinit(&alloc);
        return rc;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecFindAllPattern Vec form\n");
    
        BitVec source  = BitVecInit(base);
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Allocator/Arena.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Io.h>
    #include <Misra/Std/Log.h>
    static bool test_vec_on_arena(void) {
        ArenaAllocator arena = ArenaAllocatorInit();
        typedef Vec(int) IntVec;
        IntVec v  = VecInit(&arena);
        bool   ok = true;
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    
        // Test with int type
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Test with struct type
        typedef Vec(TestItem) TestVec;
        TestVec test_vec = VecInit(&alloc);
    
        // Test with int type and 4-byte alignment
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&aligned4);
    
        // Test with struct type and 16-byte alignment
        typedef Vec(TestItem) TestVec;
        TestVec test_vec = VecInit(&aligned16);
    
        // Test with struct type and custom copy/deinit functions
        typedef Vec(TestItem) TestVec;
        TestVec vec = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit, &alloc);
    
        // Test with struct type, custom copy/deinit functions, and 8-byte alignment
        typedef Vec(TestItem) TestVec;
        TestVec vec = VecInitWithDeepCopy(TestItemCopyInit, TestItemDeinit, &aligned8);
        WriteFmt("Testing VecInit optional allocator\n");
    
        typedef Vec(TestItem) TestVec;
    
        // Build several heaps with distinct configuration; the test verifies
    
        // Create a source vector
        typedef Vec(int) IntVec;
        IntVec src = VecInit(&alloc);
    // Main function that runs all tests
    int main(void) {
        WriteFmt("[INFO] Starting Vec.Init tests\n\n");
    
        alloc = DefaultAllocatorInit();
    
        // Run all tests using the centralized test driver
        int rc = run_test_suite(tests, total_tests, NULL, 0, "Vec.Init");
        DefaultAllocatorDeinit(&alloc);
        return rc;
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Types.h>
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    // Main function that runs all tests
    int main(void) {
        WriteFmt("[INFO] Starting Vec.Memory tests\n\n");
    
        // Array of test functions
    
        // Run all tests using the centralized test driver
        return run_test_suite(tests, total_tests, NULL, 0, "Vec.Memory");
    }
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        alloc    = DefaultAllocatorInit();
        int rc = run_test_suite(normal_tests, normal_count, NULL, 0, "Vec.Remove");
        DefaultAllocatorDeinit(&alloc);
        return rc;
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecRunLengths Vec form\n");
    
        BitVec bv = BitVecInit(base);
    #include <Misra/Std/Allocator/Heap.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Log.h>
    
        // Create a vector of ComplexItem with deep copy functions
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
    
        // Create a vector of ComplexItem with deep copy functions
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
    
        // Create a vector of ComplexItem with deep copy functions
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
    
        // Create two vectors of ComplexItem with deep copy functions
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec1 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
        ComplexVec vec2 = VecInitWithDeepCopy(ComplexItemCopyInit, ComplexItemDeinit, &alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a temporary vector with no copy_init but with copy_deinit for proper cleanup
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec temp_vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
    
        // Create a vector with no copy_init but with copy_deinit for proper cleanup
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
    
        // Create a vector with no copy_init but with copy_deinit for proper cleanup
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
    
        // Create a vector with no copy_init but with copy_deinit for proper cleanup
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
    
        // Create a vector with no copy_init but with copy_deinit for proper cleanup
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec1 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
        ComplexVec vec2 = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
    
        // Create a vector with no copy_init but with copy_deinit for proper cleanup
        typedef Vec(ComplexItem) ComplexVec;
        ComplexVec vec = VecInitWithDeepCopy(NULL, ComplexItemDeinit, &alloc);
    int main(void) {
        alloc = DefaultAllocatorInit();
        WriteFmt("[INFO] Starting Vec.Complex tests\n\n");
    
        // Array of test functions
    
        // Run all tests using the centralized test driver
        int rc = run_test_suite(tests, total_tests, NULL, 0, "Vec.Complex");
        DefaultAllocatorDeinit(&alloc);
        return rc;
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Types.h>
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Test with a vector with alignment > 1
        typedef Vec(int) AlignedIntVec;
        AlignedIntVec aligned_vec = VecInit(&aligned8);
    
        // Create a vector of integers with default alignment (1)
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector with 8-byte alignment
        typedef Vec(int) AlignedIntVec;
        AlignedIntVec aligned_vec = VecInit(&aligned8);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    // Main function that runs all tests
    int main(void) {
        WriteFmt("[INFO] Starting Vec.Access tests\n\n");
    
        // Array of test functions
    
        // Run all tests using the centralized test driver
        return run_test_suite(tests, total_tests, NULL, 0, "Vec.Access");
    }
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Types.h>
    // Test basic Vec type functionality
    bool test_vec_type_basic(void) {
        WriteFmt("Testing basic Vec type functionality\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Define a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Test with a struct type
        typedef Vec(TestItem) TestVec;
        TestVec test_vec = VecInit(&alloc);
    
        // Create a valid vector
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    // Main function that runs all tests
    int main(void) {
        WriteFmt("[INFO] Starting Vec.Type tests\n\n");
    
        // Array of test functions
    
        // Run all tests using the centralized test driver
        return run_test_suite(tests, total_tests, NULL, 0, "Vec.Type");
    }
    #include <Misra/Std/Allocator/Default.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Log.h>
    #include <Misra/Types.h> // For LVAL macro
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec1 = VecInit(&alloc);
        WriteFmt("Testing manual clone allocator inheritance\n");
    
        typedef Vec(int) IntVec;
    
        HeapAllocator local_heap = HeapAllocatorInit();
    
        // Create a vector of integers
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    
        // Create a vector of integers without copy_init
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
        WriteFmt("Testing VecInsertRangeFast with count > (length - idx)\n");
    
        typedef Vec(int) IntVec;
        IntVec vec = VecInit(&alloc);
    int main(void) {
        alloc = DefaultAllocatorInit();
        WriteFmt("[INFO] Starting Vec.Insert tests\n\n");
    
        // Array of test functions
    
        // Run all tests using the centralized test driver
        int rc = run_test_suite(tests, total_tests, NULL, 0, "Vec.Insert");
        DefaultAllocatorDeinit(&alloc);
        return rc;
    
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Vec/Type.h>
    #include <Misra/Types.h>
    /// canonical Cstr / Zstr / unsuffixed-Str overload family.
    typedef const char *Zstr;
    typedef Vec(Zstr) Zstrs;
    
    ///
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    
    #if FEATURE_BITVEC
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
        } ArgSpec;
    
        typedef Vec(ArgSpec) ArgSpecs;
    
        ///
    #define MISRA_STD_UTILITY_STR_ITER_H
    
    #include <Misra/Std/Container/Vec/Type.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Utility/Iter.h>
    
    typedef Iter(char) StrIter;
    typedef Vec(StrIter) StrIters;
    
    ///
    #include <Misra/Std/Container/Map.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Sys/Backtrace.h>
        } DebugFreedEntry;
    
        typedef Vec(DebugFreedEntry) DebugFreedVec;
    
        ///
    #define MISRA_STD_CONTAINER_BUF_H
    
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Utility/Iter.h>
    #include <Misra/Types.h>
    
    typedef Vec(u8) Buf;
    
    /// Iterator over an immutable byte buffer. Layout matches `Iter(const u8)`
    
    // clang-format off
    #include "Vec/Type.h"
    #include "Vec/Init.h"
    #include "Vec/Insert.h"
    // clang-format off
    #include "Vec/Type.h"
    #include "Vec/Init.h"
    #include "Vec/Insert.h"
    #include "Vec/Remove.h"
    #include "Vec/Type.h"
    #include "Vec/Init.h"
    #include "Vec/Insert.h"
    #include "Vec/Remove.h"
    #include "Vec/Access.h"
    #include "Vec/Init.h"
    #include "Vec/Insert.h"
    #include "Vec/Remove.h"
    #include "Vec/Access.h"
    #include "Vec/Memory.h"
    #include "Vec/Insert.h"
    #include "Vec/Remove.h"
    #include "Vec/Access.h"
    #include "Vec/Memory.h"
    #include "Vec/Foreach.h"
    #include "Vec/Remove.h"
    #include "Vec/Access.h"
    #include "Vec/Memory.h"
    #include "Vec/Foreach.h"
    #include "Vec/Ops.h"
    #include "Vec/Access.h"
    #include "Vec/Memory.h"
    #include "Vec/Foreach.h"
    #include "Vec/Ops.h"
    #include "Vec/Private.h"
    #include "Vec/Memory.h"
    #include "Vec/Foreach.h"
    #include "Vec/Ops.h"
    #include "Vec/Private.h"
    // clang-format on
    #include "Vec/Foreach.h"
    #include "Vec/Ops.h"
    #include "Vec/Private.h"
    // clang-format on
    #define MISRA_STD_CONTAINER_GRAPH_TYPE_H
    
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
    /// TAGS: Graph, Edge, Neighbor, Vec
    ///
    typedef Vec(GraphNodeId) GraphNeighbors;
    
    ///
    } GenericGraphSlot;
    
    typedef Vec(GenericGraphSlot) GraphSlots;
    typedef Vec(u32) GraphFreeIndices;
    
    typedef Vec(GenericGraphSlot) GraphSlots;
    typedef Vec(u32) GraphFreeIndices;
    
    ///
    } GraphPendingEdgeRemoval;
    
    typedef Vec(GraphPendingEdgeRemoval) GraphPendingEdgeRemovals;
    
    typedef struct {
    #define Graph(T)                                                                                                       \
        struct {                                                                                                           \
            Vec(GraphSlot(T)) slots;                                                                                       \
            GraphFreeIndices         free_indices;                                                                         \
            GraphPendingEdgeRemovals pending_edge_removals;                                                                \
             UNPL(_s).done == 0;                                                                                           \
             MemSet(UNPL(_s).d, 0, sizeof(UNPL(_s).d)), UNPL(_s).done = 1)                                                 \
            for (Vec(T) name = {.length      = 0,                                                                          \
                                .capacity    = (ne),                                                                       \
                                .copy_init   = NULL,                                                                       \
    #include <Misra/Std/Container/Common.h>
    #include <Misra/Types.h>
    #include <Misra/Std/Container/Vec.h>
    
    ///
    } BitVec;
    
    typedef Vec(BitVec) BitVecs;
    
    ///
    /// TAGS: BitVec, Type, Match
    ///
    typedef Vec(size) BitVecMatchIndices;
    
    ///
    /// TAGS: BitVec, Type, Run
    ///
    typedef Vec(BitVecRun) BitVecRuns;
    
    #define BITVEC_MAGIC MAKE_NEW_MAGIC_VALUE("bitvectr")
    #include <Misra/Std/Memory.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Std/Container/Vec/Type.h>
    
    #ifdef __cplusplus
    
    #include "Type.h"
    #include <Misra/Std/Container/Vec/Access.h>
    
    #ifdef __cplusplus
    
    #include "Type.h"
    #include <Misra/Std/Container/Vec/Insert.h>
    #include <Misra/Std/Zstr.h>
    #define MISRA_STD_CONTAINER_STR_TYPE_H
    
    #include <Misra/Std/Container/Vec/Type.h>
    #include <Misra/Std/Utility/Iter/Type.h>
    #include <Misra/Types.h>
    /// TAGS: Str, Type, API
    ///
    typedef Vec(char) Str;
    
    ///
    /// TAGS: Str, Type, Vector
    ///
    typedef Vec(Str) Strs;
    
    ///
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
    } ProcMapEntry;
    
    typedef Vec(ProcMapEntry) ProcMapEntries;
    
    typedef struct ProcMaps {
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
    /// TAGS: Backtrace, Type, Frame
    ///
    typedef Vec(StackFrame) StackFrames;
    
    // ---------------------------------------------------------------------------
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str/Type.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
    } MachoCacheEntry;
    
    typedef Vec(MachoCacheEntry) MachoCacheEntries;
    
    typedef struct MachoCache {
    
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    /// Vector type for directory contents.
    ///
    typedef Vec(DirEntry) DirContents;
    
    // Path-arg dispatch. Library design: `Str *` is the canonical path
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Sys/Socket.h>
    #include <Misra/Types.h>
        } HostsEntry;
    
        typedef Vec(HostsEntry) HostsTable;
        typedef Vec(SocketAddr) DnsAddrs;
    
        typedef Vec(HostsEntry) HostsTable;
        typedef Vec(SocketAddr) DnsAddrs;
    
        ///
    #endif
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Sys/ProcMaps.h>
    #include <Misra/Types.h>
    } ResolverCacheEntry;
    
    typedef Vec(ResolverCacheEntry) ResolverCache;
    
    typedef struct SymbolResolver {
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str/Type.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
    } PdbCacheEntry;
    
    typedef Vec(PdbCacheEntry) PdbCacheEntries;
    
    typedef struct PdbCache {
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    } PeSection;
    
    typedef Vec(PeSection) PeSections;
    
    ///
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    } PdbFunction;
    
    typedef Vec(PdbFunction) PdbFunctions;
    
    ///
    #include <Misra/Std/Allocator.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
    } DwarfLineEntry;
    
    typedef Vec(DwarfLineEntry) DwarfLineEntries;
    
    ///
    } DwarfFde;
    
    typedef Vec(DwarfCie) DwarfCies;
    typedef Vec(DwarfFde) DwarfFdes;
    
    typedef Vec(DwarfCie) DwarfCies;
    typedef Vec(DwarfFde) DwarfFdes;
    
    ///
    } DwarfFunction;
    
    typedef Vec(DwarfFunction) DwarfFunctionEntries;
    
    ///
    #define HttpHeaderInit_1(alloc_ptr) ((HttpHeader) {.key = StrInit_1(alloc_ptr), .value = StrInit_1(alloc_ptr)})
    
    typedef Vec(HttpHeader) HttpHeaders;
    
    ///
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    } ElfSymbol;
    
    typedef Vec(ElfSection) ElfSections;
    typedef Vec(ElfSymbol) ElfSymbols;
    
    typedef Vec(ElfSection) ElfSections;
    typedef Vec(ElfSymbol) ElfSymbols;
    
    ///
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Std/Zstr.h>
    #include <Misra/Types.h>
    } MachoSymbol;
    
    typedef Vec(MachoSegment) MachoSegments;
    typedef Vec(MachoSection) MachoSections;
    typedef Vec(MachoSymbol) MachoSymbols;
    
    typedef Vec(MachoSegment) MachoSegments;
    typedef Vec(MachoSection) MachoSections;
    typedef Vec(MachoSymbol) MachoSymbols;
    typedef Vec(MachoSegment) MachoSegments;
    typedef Vec(MachoSection) MachoSections;
    typedef Vec(MachoSymbol) MachoSymbols;
    
    ///
    #include <Misra/Std/Container/Str.h>
    #include <Misra/Std/Container/Buf.h>
    #include <Misra/Std/Container/Vec.h>
    #include <Misra/Types.h>
        } DnsRecord;
    
        typedef Vec(DnsRecord) DnsRecords;
    
        ///
Last updated on