Skip to content

OVERLOAD

Description

Variadic macro overload by argument count. Dispatches a call OVERLOAD(Name, ...) to Name_<N>(...) where N is the argument count returned by NARG. The caller is responsible for defining each overload (Name_0, Name_1, …) that they want to accept.

Usage:

#define MyInit(…) OVERLOAD(MyInit, VA_ARGS) #define MyInit_0() MyInit_1(MisraScope) #define MyInit_1(p) { …, .allocator = ALLOCATOR_OF(p) }

Two indirections so NARG fully expands before the ## concatenation in OVERLOAD__.

Usage example (Cross-references)

Usage examples (Cross-references)
    ///
    bool float_try_to_decimal_str(Str *out, Float *value, u32 precision, bool has_precision, Allocator *alloc);
    #    define FloatTryToDecimalStr(...) OVERLOAD(FloatTryToDecimalStr, __VA_ARGS__)
    #    define FloatTryToDecimalStr_4(out, value, precision, has_precision)                                               \
            float_try_to_decimal_str((out), (value), (precision), (has_precision), MisraScope)
        Allocator *alloc
    );
    #    define FloatTryToScientificStr(...) OVERLOAD(FloatTryToScientificStr, __VA_ARGS__)
    #    define FloatTryToScientificStr_5(out, value, precision, has_precision, uppercase)                                 \
            float_try_to_scientific_str((out), (value), (precision), (has_precision), (uppercase), MisraScope)
    i64 file_read_to_str(File *f, Str *out);
    i64 file_read_to_buf(File *f, Buf *out);
    #define FileRead(...) OVERLOAD(FileRead, __VA_ARGS__)
    #define FileRead_2(f, out)                                                                                             \
        _Generic((out), Buf *: file_read_to_buf((f), (Buf *)(out)), Str *: file_read_to_str((f), (Str *)(out)))
    i64 file_write_and_close_from_str(Zstr path, const Str *in);
    i64 file_write_and_close_from_bytes(Zstr path, const void *buf, u64 n);
    #define FileWriteAndClose(...) OVERLOAD(FileWriteAndClose, __VA_ARGS__)
    #define FileWriteAndClose_2(path, container)                                                                           \
        _Generic(                                                                                                          \
    ///
    File file_open_temp(Str *out_path, Allocator *alloc);
    #define FileOpenTemp(...)               OVERLOAD(FileOpenTemp, __VA_ARGS__)
    #define FileOpenTemp_1(out_path)        file_open_temp((out_path), MisraScope)
    #define FileOpenTemp_2(out_path, alloc) file_open_temp((out_path), ALLOCATOR_OF(alloc))
    /// TAGS: Zstr, Allocation
    Zstr zstr_dup_n(Zstr src, size n, Allocator *alloc);
    #define ZstrDupN(...)             OVERLOAD(ZstrDupN, __VA_ARGS__)
    #define ZstrDupN_2(src, n)        zstr_dup_n((src), (n), MisraScope)
    #define ZstrDupN_3(src, n, alloc) zstr_dup_n((src), (n), ALLOCATOR_OF(alloc))
    /// TAGS: Zstr, Allocation
    Zstr zstr_dup(Zstr src, Allocator *alloc);
    #define ZstrDup(...)          OVERLOAD(ZstrDup, __VA_ARGS__)
    #define ZstrDup_1(src)        zstr_dup((src), MisraScope)
    #define ZstrDup_2(src, alloc) zstr_dup((src), ALLOCATOR_OF(alloc))
        ///          surfaces from later spec-Vec growth.
        ///
    #define ArgParseInit(...)                     OVERLOAD(ArgParseInit, __VA_ARGS__)
    #define ArgParseInit_2(prog_name, prog_about) ArgParseInit_3((prog_name), (prog_about), MisraScope)
    #define ArgParseInit_3(prog_name, prog_about, alloc_ptr)                                                               \
    /// TAGS: Graph, Init, Construct
    ///
    #define GraphInit(...)               OVERLOAD(GraphInit, __VA_ARGS__)
    #define GraphInit_0()                GraphInitWithDeepCopy_3(NULL, NULL, MisraScope)
    #define GraphInit_1(typed_alloc_ptr) GraphInitWithDeepCopy_3(NULL, NULL, typed_alloc_ptr)
    /// TAGS: Graph, Init, Typed, Construct
    ///
    #define GraphInitT(g, ...)               OVERLOAD(GraphInitT, g, __VA_ARGS__)
    #define GraphInitT_1(g)                  GraphInitWithDeepCopyT_4((g), NULL, NULL, MisraScope)
    #define GraphInitT_2(g, typed_alloc_ptr) GraphInitWithDeepCopyT_4((g), NULL, NULL, typed_alloc_ptr)
    /// TAGS: Graph, Init, DeepCopy, Construct
    ///
    #define GraphInitWithDeepCopy(...)                       OVERLOAD(GraphInitWithDeepCopy, __VA_ARGS__)
    #define GraphInitWithDeepCopy_2(ci, cd)                  GRAPH_INIT_WITH_DEEP_COPY_VALUE((ci), (cd), MisraScope)
    #define GraphInitWithDeepCopy_3(ci, cd, typed_alloc_ptr) GRAPH_INIT_WITH_DEEP_COPY_VALUE((ci), (cd), typed_alloc_ptr)
    /// TAGS: Graph, Init, DeepCopy, Typed, Construct
    ///
    #define GraphInitWithDeepCopyT(g, ...) OVERLOAD(GraphInitWithDeepCopyT, g, __VA_ARGS__)
    #ifdef __cplusplus
    #    define GraphInitWithDeepCopyT_3(g, ci, cd) (TYPE_OF(g) GRAPH_INIT_WITH_DEEP_COPY_VALUE((ci), (cd), MisraScope))
    /// TAGS: List, Init, API
    ///
    #define ListInit(...)               OVERLOAD(ListInit, __VA_ARGS__)
    #define ListInit_0()                ListInitWithDeepCopy_3(NULL, NULL, MisraScope)
    #define ListInit_1(typed_alloc_ptr) ListInitWithDeepCopy_3(NULL, NULL, typed_alloc_ptr)
    /// TAGS: List, Init, API
    ///
    #define ListInitT(l, ...)               OVERLOAD(ListInitT, l, __VA_ARGS__)
    #define ListInitT_1(l)                  ListInitWithDeepCopyT_4(l, NULL, NULL, MisraScope)
    #define ListInitT_2(l, typed_alloc_ptr) ListInitWithDeepCopyT_4(l, NULL, NULL, typed_alloc_ptr)
    /// TAGS: List, Init, DeepCopy, Copy
    ///
    #define ListInitWithDeepCopy(...)      OVERLOAD(ListInitWithDeepCopy, __VA_ARGS__)
    #define ListInitWithDeepCopy_2(ci, cd) ListInitWithDeepCopy_3(ci, cd, MisraScope)
    #define ListInitWithDeepCopy_3(ci, cd, typed_alloc_ptr)                                                                \
         .__magic     = LIST_MAGIC}
    
    #define ListInitWithDeepCopyT(l, ...) OVERLOAD(ListInitWithDeepCopyT, l, __VA_ARGS__)
    #ifdef __cplusplus
    #    define ListInitWithDeepCopyT_3(l, ci, cd) (TYPE_OF(l) ListInitWithDeepCopy_3(ci, cd, MisraScope))
    /// TAGS: Float, Init, Zero, Construct
    ///
    #define FloatInit(...)             OVERLOAD(FloatInit, __VA_ARGS__)
    #define FloatInit_0()              ((Float) {.negative = false, .significand = IntInit_1(MisraScope), .exponent = 0})
    #define FloatInit_1(allocator_ptr) ((Float) {.negative = false, .significand = IntInit_1(allocator_ptr), .exponent = 0})
        Float float_from_str_zstr(Zstr text, Allocator *alloc);
        Float float_from_str_str(const Str *text, Allocator *alloc);
    #define FloatFromStr(...) OVERLOAD(FloatFromStr, __VA_ARGS__)
    #define FloatFromStr_1(text)                                                                                           \
        _Generic((text), Str *: float_from_str_str, Zstr: float_from_str_zstr, char *: float_from_str_zstr)(               \
    /// TAGS: Float, Convert, String, Decimal
    ///
    #define FloatTryToStr(...)                 OVERLOAD(FloatTryToStr, __VA_ARGS__)
    #define FloatTryToStr_2(out, value)        float_try_to_str((out), (value), FloatAllocator((value)))
    #define FloatTryToStr_3(out, value, alloc) float_try_to_str((out), (value), (alloc))
    /// TAGS: Float, Convert, String, Decimal
    ///
    #define FloatToStr(...)            OVERLOAD(FloatToStr, __VA_ARGS__)
    #define FloatToStr_1(value)        float_to_str((value), FloatAllocator((value)))
    #define FloatToStr_2(value, alloc) float_to_str((value), (alloc))
    /// TAGS: Int, Init, Zero, Construct
    ///
    #define IntInit(...)             OVERLOAD(IntInit, __VA_ARGS__)
    #define IntInit_0()              ((Int) {.bits = BitVecInit_1(MisraScope)})
    #define IntInit_1(allocator_ptr) ((Int) {.bits = BitVecInit_1(allocator_ptr)})
        ///
        Int int_from_bytes_le(const u8 *bytes, u64 len, Allocator *alloc);
    #define IntFromBytesLE(...)                 OVERLOAD(IntFromBytesLE, __VA_ARGS__)
    #define IntFromBytesLE_2(bytes, len)        int_from_bytes_le((bytes), (len), MisraScope)
    #define IntFromBytesLE_3(bytes, len, alloc) int_from_bytes_le((bytes), (len), ALLOCATOR_OF(alloc))
        ///
        Int int_from_bytes_be(const u8 *bytes, u64 len, Allocator *alloc);
    #define IntFromBytesBE(...)                 OVERLOAD(IntFromBytesBE, __VA_ARGS__)
    #define IntFromBytesBE_2(bytes, len)        int_from_bytes_be((bytes), (len), MisraScope)
    #define IntFromBytesBE_3(bytes, len, alloc) int_from_bytes_be((bytes), (len), ALLOCATOR_OF(alloc))
        Int int_from_str_radix_zstr(Zstr digits, u8 radix, Allocator *alloc);
        Int int_from_str_radix_str(const Str *digits, u8 radix, Allocator *alloc);
    #define IntFromStrRadix(...) OVERLOAD(IntFromStrRadix, __VA_ARGS__)
    #define IntFromStrRadix_2(digits, radix)                                                                               \
        _Generic((digits), Str *: int_from_str_radix_str, Zstr: int_from_str_radix_zstr, char *: int_from_str_radix_zstr)( \
        Int int_from_str_zstr(Zstr decimal, Allocator *alloc);
        Int int_from_str_str(const Str *decimal, Allocator *alloc);
    #define IntFromStr(...) OVERLOAD(IntFromStr, __VA_ARGS__)
    #define IntFromStr_1(decimal)                                                                                          \
        _Generic((decimal), Str *: int_from_str_str, Zstr: int_from_str_zstr, char *: int_from_str_zstr)(                  \
        Int int_from_binary_zstr(Zstr binary, Allocator *alloc);
        Int int_from_binary_str(const Str *binary, Allocator *alloc);
    #define IntFromBinary(...) OVERLOAD(IntFromBinary, __VA_ARGS__)
    #define IntFromBinary_1(binary)                                                                                        \
        _Generic((binary), Str *: int_from_binary_str, Zstr: int_from_binary_zstr, char *: int_from_binary_zstr)(          \
        Int int_from_oct_str_zstr(Zstr octal, Allocator *alloc);
        Int int_from_oct_str_str(const Str *octal, Allocator *alloc);
    #define IntFromOctStr(...) OVERLOAD(IntFromOctStr, __VA_ARGS__)
    #define IntFromOctStr_1(octal)                                                                                         \
        _Generic((octal), Str *: int_from_oct_str_str, Zstr: int_from_oct_str_zstr, char *: int_from_oct_str_zstr)(        \
        Int int_from_hex_str_zstr(Zstr hex, Allocator *alloc);
        Int int_from_hex_str_str(const Str *hex, Allocator *alloc);
    #define IntFromHexStr(...) OVERLOAD(IntFromHexStr, __VA_ARGS__)
    #define IntFromHexStr_1(hex)                                                                                           \
        _Generic((hex), Str *: int_from_hex_str_str, Zstr: int_from_hex_str_zstr, char *: int_from_hex_str_zstr)(          \
    /// TAGS: Int, Convert, String
    ///
    #define IntTryToStr(...)                 OVERLOAD(IntTryToStr, __VA_ARGS__)
    #define IntTryToStr_2(out, value)        int_try_to_str((out), (value), IntAllocator((value)))
    #define IntTryToStr_3(out, value, alloc) int_try_to_str((out), (value), (alloc))
    /// TAGS: Int, Convert, String
    ///
    #define IntToStr(...)            OVERLOAD(IntToStr, __VA_ARGS__)
    #define IntToStr_1(value)        int_to_str((value), IntAllocator((value)))
    #define IntToStr_2(value, alloc) int_to_str((value), (alloc))
    /// TAGS: Int, Convert, Radix, String
    ///
    #define IntTryToStrRadix(...) OVERLOAD(IntTryToStrRadix, __VA_ARGS__)
    #define IntTryToStrRadix_4(out, value, radix, uppercase)                                                               \
        int_try_to_str_radix((out), (value), (radix), (uppercase), IntAllocator((value)))
    /// TAGS: Int, Convert, Radix, String
    ///
    #define IntToStrRadix(...) OVERLOAD(IntToStrRadix, __VA_ARGS__)
    #define IntToStrRadix_3(value, radix, uppercase)                                                                       \
        int_to_str_radix((value), (radix), (uppercase), IntAllocator((value)))
    /// TAGS: Init, Vec, Length, Size
    ///
    #define VecInit(...) OVERLOAD(VecInit, __VA_ARGS__)
    #define VecInit_0()  VecInit_1(MisraScope)
    #define VecInit_1(allocator_ptr)                                                                                       \
    /// TAGS: Vec, Init, API
    ///
    #define VecInitT(v, ...) OVERLOAD(VecInitT, v, __VA_ARGS__)
    #ifdef __cplusplus
    #    define VecInitT_1(v)            (TYPE_OF(v) VecInit_1(MisraScope))
    /// TAGS: Vec, Init, DeepCopy, Copy
    ///
    #define VecInitWithDeepCopy(...)      OVERLOAD(VecInitWithDeepCopy, __VA_ARGS__)
    #define VecInitWithDeepCopy_2(ci, cd) VecInitWithDeepCopy_3(ci, cd, MisraScope)
    #define VecInitWithDeepCopy_3(ci, cd, allocator_ptr)                                                                   \
         .__magic     = VEC_MAGIC}
    
    #define VecInitWithDeepCopyT(v, ...) OVERLOAD(VecInitWithDeepCopyT, v, __VA_ARGS__)
    #ifdef __cplusplus
    #    define VecInitWithDeepCopyT_3(v, ci, cd)            (TYPE_OF(v) VecInitWithDeepCopy_3(ci, cd, MisraScope))
    /// TAGS: BitVec, Init, API
    ///
    #define BitVecInit(...) OVERLOAD(BitVecInit, __VA_ARGS__)
    #define BitVecInit_0()  BitVecInit_1(MisraScope)
    #ifdef __cplusplus
        ///
        BitVec bitvec_init_with_capacity(u64 cap, Allocator *alloc);
    #define BitVecInitWithCapacity(...)         OVERLOAD(BitVecInitWithCapacity, __VA_ARGS__)
    #define BitVecInitWithCapacity_1(cap)         bitvec_init_with_capacity((cap), MisraScope)
    #define BitVecInitWithCapacity_2(cap, alloc)  bitvec_init_with_capacity((cap), ALLOCATOR_OF(alloc))
        bool bitvec_find_all_pattern_vec(BitVec *bv, BitVec *pattern, BitVecMatchIndices *out);
    
    #define BitVecFindAllPattern(...)                         OVERLOAD(BitVecFindAllPattern, __VA_ARGS__)
    #define BitVecFindAllPattern_4(bv, pattern, results, max) bitvec_find_all_pattern_raw((bv), (pattern), (results), (max))
    #define BitVecFindAllPattern_3(bv, pattern, out_vec)      bitvec_find_all_pattern_vec((bv), (pattern), (out_vec))
        bool bitvec_try_from_str_zstr(BitVec *out, Zstr str, Allocator *alloc);
        bool bitvec_try_from_str_str(BitVec *out, const Str *str, Allocator *alloc);
    #define BitVecTryFromStr(...) OVERLOAD(BitVecTryFromStr, __VA_ARGS__)
    #define BitVecTryFromStr_2(out, str)                                                                                   \
        _Generic((str), Str *: bitvec_try_from_str_str, Zstr: bitvec_try_from_str_zstr, char *: bitvec_try_from_str_zstr)( \
        BitVec bitvec_from_str_zstr(Zstr str, Allocator *alloc);
        BitVec bitvec_from_str_str(const Str *str, Allocator *alloc);
    #define BitVecFromStr(...) OVERLOAD(BitVecFromStr, __VA_ARGS__)
    #define BitVecFromStr_1(str)                                                                                           \
        _Generic((str), Str *: bitvec_from_str_str, Zstr: bitvec_from_str_zstr, char *: bitvec_from_str_zstr)(             \
        ///
        bool bitvec_try_from_bytes(BitVec *out, const u8 *bytes, u64 bit_len, Allocator *alloc);
    #define BitVecTryFromBytes(...)                   OVERLOAD(BitVecTryFromBytes, __VA_ARGS__)
    #define BitVecTryFromBytes_3(out, bytes, bit_len) bitvec_try_from_bytes((out), (bytes), (bit_len), MisraScope)
    #define BitVecTryFromBytes_4(out, bytes, bit_len, alloc)                                                               \
        ///
        BitVec bitvec_from_bytes(const u8 *bytes, u64 bit_len, Allocator *alloc);
    #define BitVecFromBytes(...)                     OVERLOAD(BitVecFromBytes, __VA_ARGS__)
    #define BitVecFromBytes_2(bytes, bit_len)        bitvec_from_bytes((bytes), (bit_len), MisraScope)
    #define BitVecFromBytes_3(bytes, bit_len, alloc) bitvec_from_bytes((bytes), (bit_len), ALLOCATOR_OF(alloc))
        ///
        bool bitvec_try_from_integer(BitVec *out, u64 value, u64 bits, Allocator *alloc);
    #define BitVecTryFromInteger(...)                OVERLOAD(BitVecTryFromInteger, __VA_ARGS__)
    #define BitVecTryFromInteger_3(out, value, bits) bitvec_try_from_integer((out), (value), (bits), MisraScope)
    #define BitVecTryFromInteger_4(out, value, bits, alloc)                                                                \
        ///
        BitVec bitvec_from_integer(u64 value, u64 bits, Allocator *alloc);
    #define BitVecFromInteger(...)                  OVERLOAD(BitVecFromInteger, __VA_ARGS__)
    #define BitVecFromInteger_2(value, bits)        bitvec_from_integer((value), (bits), MisraScope)
    #define BitVecFromInteger_3(value, bits, alloc) bitvec_from_integer((value), (bits), ALLOCATOR_OF(alloc))
    /// TAGS: BitVec, Convert, String
    ///
    #define BitVecTryToStr(...)              OVERLOAD(BitVecTryToStr, __VA_ARGS__)
    #define BitVecTryToStr_2(out, bv)        bitvec_try_to_str((out), (bv), BitVecAllocator((bv)))
    #define BitVecTryToStr_3(out, bv, alloc) bitvec_try_to_str((out), (bv), (alloc))
    /// TAGS: BitVec, Convert, String
    ///
    #define BitVecToStr(...)         OVERLOAD(BitVecToStr, __VA_ARGS__)
    #define BitVecToStr_1(bv)        bitvec_to_str((bv), BitVecAllocator((bv)))
    #define BitVecToStr_2(bv, alloc) bitvec_to_str((bv), (alloc))
        bool bitvec_run_lengths_vec(BitVec *bv, BitVecRuns *out);
    
    #define BitVecRunLengths(...)                     OVERLOAD(BitVecRunLengths, __VA_ARGS__)
    #define BitVecRunLengths_4(bv, runs, values, max) bitvec_run_lengths_raw((bv), (runs), (values), (max))
    #define BitVecRunLengths_2(bv, out_vec)           bitvec_run_lengths_vec((bv), (out_vec))
    /// TAGS: Str, Init, Cstr, API
    ///
    #define StrInitFromCstr(...)                OVERLOAD(StrInitFromCstr, __VA_ARGS__)
    #define StrInitFromCstr_2(cstr, len)        str_init_from_cstr((cstr), (len), MisraScope)
    #define StrInitFromCstr_3(cstr, len, alloc) str_init_from_cstr((cstr), (len), ALLOCATOR_OF(alloc))
    /// TAGS: Str, Init, Zstr, API
    ///
    #define StrInitFromZstr(...)       OVERLOAD(StrInitFromZstr, __VA_ARGS__)
    #define StrInitFromZstr_1(zstr)    StrInitFromCstr_2((zstr), ZstrLen(zstr))
    #define StrInitFromZstr_2(zstr, a) StrInitFromCstr_3((zstr), ZstrLen(zstr), (a))
    /// TAGS: Str, Init, Zstr, Alias, API
    ///
    #define StrZ(...)       OVERLOAD(StrZ, __VA_ARGS__)
    #define StrZ_1(zstr)    StrInitFromZstr_1((zstr))
    #define StrZ_2(zstr, a) StrInitFromZstr_2((zstr), (a))
    /// TAGS: Str, Init, Copy, API
    ///
    #define StrInitFromStr(...)      OVERLOAD(StrInitFromStr, __VA_ARGS__)
    #define StrInitFromStr_1(str)    StrInitFromCstr_2(StrBegin(str), StrLen(str))
    #define StrInitFromStr_2(str, a) StrInitFromCstr_3(StrBegin(str), StrLen(str), (a))
    /// TAGS: Str, Init, Copy, Alias, API
    ///
    #define StrDup(...)      OVERLOAD(StrDup, __VA_ARGS__)
    #define StrDup_1(str)    StrInitFromStr_1((str))
    #define StrDup_2(str, a) StrInitFromStr_2((str), (a))
    /// TAGS: Str, Init, API
    ///
    #define StrInit(...) OVERLOAD(StrInit, __VA_ARGS__)
    #ifdef __cplusplus
    #    define StrInit_0()          (Str VecInit_1(MisraScope))
    /// TAGS: Str, Compare
    ///
    #define StrCmp(...) OVERLOAD(StrCmp, __VA_ARGS__)
    #define StrCmp_2(s, other)                                                                                             \
        _Generic(                                                                                                          \
    /// TAGS: Str, Compare, IgnoreCase
    ///
    #define StrCmpIgnoreCase(...) OVERLOAD(StrCmpIgnoreCase, __VA_ARGS__)
    #define StrCmpIgnoreCase_2(s, other)                                                                                   \
        _Generic(                                                                                                          \
    /// TAGS: Str, Find, Search
    ///
    #define StrFind(...) OVERLOAD(StrFind, __VA_ARGS__)
    #define StrFind_2(s, key)                                                                                              \
        _Generic(                                                                                                          \
    /// TAGS: Str, IndexOf, Search
    ///
    #define StrIndexOf(...) OVERLOAD(StrIndexOf, __VA_ARGS__)
    #define StrIndexOf_2(s, key)                                                                                           \
        _Generic(                                                                                                          \
    /// TAGS: Str, Contains, Search
    ///
    #define StrContains(...) OVERLOAD(StrContains, __VA_ARGS__)
    #define StrContains_2(s, key)                                                                                          \
        _Generic(                                                                                                          \
    /// TAGS: Str, StartsWith, Prefix
    ///
    #define StrStartsWith(...) OVERLOAD(StrStartsWith, __VA_ARGS__)
    #define StrStartsWith_2(s, prefix)                                                                                     \
        _Generic(                                                                                                          \
    /// TAGS: Str, EndsWith, Suffix
    ///
    #define StrEndsWith(...) OVERLOAD(StrEndsWith, __VA_ARGS__)
    #define StrEndsWith_2(s, suffix)                                                                                       \
        _Generic(                                                                                                          \
    /// TAGS: Str, Replace
    ///
    #define StrReplace(...) OVERLOAD(StrReplace, __VA_ARGS__)
    #define StrReplace_4(s, match, replacement, count)                                                                     \
        _Generic(                                                                                                          \
    /// TAGS: Str, Insert, Range, Zstr, Cstr
    ///
    #define StrInsertMany(...) OVERLOAD(StrInsertMany, __VA_ARGS__)
    #define StrInsertMany_3(str, zstr, idx)                                                                            \
        _Generic((zstr), Zstr: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, Insert, Range, Zstr, Cstr, Must, Abort
    ///
    #define StrMustInsertMany(...) OVERLOAD(StrMustInsertMany, __VA_ARGS__)
    #define StrMustInsertMany_3(str, zstr, idx)                                                                        \
        _Generic((zstr), Zstr: VecMustInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecMustInsertRangeR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, Insert, Range, Zstr, Cstr, Fast, Unordered
    ///
    #define StrInsertManyFast(...) OVERLOAD(StrInsertManyFast, __VA_ARGS__)
    #define StrInsertManyFast_3(str, zstr, idx)                                                                        \
        _Generic((zstr), Zstr: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, Insert, Range, Zstr, Cstr, Fast, Unordered, Must, Abort
    ///
    #define StrMustInsertManyFast(...) OVERLOAD(StrMustInsertManyFast, __VA_ARGS__)
    #define StrMustInsertManyFast_3(str, zstr, idx)                                                                    \
        _Generic((zstr), Zstr: VecMustInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))), char *: VecMustInsertRangeFastR((str), (Zstr)(zstr), (idx), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, PushBack, Range, Zstr, Cstr
    ///
    #define StrPushBackMany(...) OVERLOAD(StrPushBackMany, __VA_ARGS__)
    #define StrPushBackMany_2(str, zstr)                                                                               \
        _Generic((zstr), Zstr: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, PushBack, Range, Zstr, Cstr, Must, Abort
    ///
    #define StrMustPushBackMany(...) OVERLOAD(StrMustPushBackMany, __VA_ARGS__)
    #define StrMustPushBackMany_2(str, zstr)                                                                           \
        _Generic((zstr), Zstr: VecMustPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushBackArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, PushFront, Range, Zstr, Cstr
    ///
    #define StrPushFrontMany(...) OVERLOAD(StrPushFrontMany, __VA_ARGS__)
    #define StrPushFrontMany_2(str, zstr)                                                                              \
        _Generic((zstr), Zstr: VecPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, PushFront, Range, Zstr, Cstr, Must, Abort
    ///
    #define StrMustPushFrontMany(...) OVERLOAD(StrMustPushFrontMany, __VA_ARGS__)
    #define StrMustPushFrontMany_2(str, zstr)                                                                          \
        _Generic((zstr), Zstr: VecMustPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushFrontArrR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, PushFront, Range, Zstr, Cstr, Fast, Unordered
    ///
    #define StrPushFrontManyFast(...) OVERLOAD(StrPushFrontManyFast, __VA_ARGS__)
    #define StrPushFrontManyFast_2(str, zstr)                                                                          \
        _Generic((zstr), Zstr: VecPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
    /// TAGS: Str, PushFront, Range, Zstr, Cstr, Fast, Unordered, Must, Abort
    ///
    #define StrMustPushFrontManyFast(...) OVERLOAD(StrMustPushFrontManyFast, __VA_ARGS__)
    #define StrMustPushFrontManyFast_2(str, zstr)                                                                      \
        _Generic((zstr), Zstr: VecMustPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))), char *: VecMustPushFrontArrFastR((str), (Zstr)(zstr), ZstrLen((Zstr)(zstr))))
         .__magic           = MAP_MAGIC}
    
    #define MapInitFull(...) OVERLOAD(MapInitFull, __VA_ARGS__)
    #define MapInitFull_8(hash_fn, compare_fn, vcmp, kci, kcd, vci, vcd, policy_value)                                     \
        MapInitFull_9(hash_fn, compare_fn, vcmp, kci, kcd, vci, vcd, policy_value, MisraScope)
    /// TAGS: Map, Init, API
    ///
    #define MapInit(...)                   OVERLOAD(MapInit, __VA_ARGS__)
    #define MapInit_2(hash_fn, compare_fn) MapInit_3(hash_fn, compare_fn, MisraScope)
    #define MapInit_3(hash_fn, compare_fn, typed_alloc_ptr)                                                                \
    /// TAGS: Map, Compare, Value, Init
    ///
    #define MapInitWithValueCompare(...) OVERLOAD(MapInitWithValueCompare, __VA_ARGS__)
    #define MapInitWithValueCompare_3(hash_fn, compare_fn, value_compare_fn)                                               \
        MapInitWithValueCompare_4(hash_fn, compare_fn, value_compare_fn, MisraScope)
    /// TAGS: Map, Policy, Init
    ///
    #define MapInitWithPolicy(...) OVERLOAD(MapInitWithPolicy, __VA_ARGS__)
    #define MapInitWithPolicy_3(hash_fn, compare_fn, policy_value)                                                         \
        MapInitWithPolicy_4(hash_fn, compare_fn, policy_value, MisraScope)
    /// TAGS: Map, Compare, Value, Policy, Init
    ///
    #define MapInitWithValueCompareAndPolicy(...) OVERLOAD(MapInitWithValueCompareAndPolicy, __VA_ARGS__)
    #define MapInitWithValueCompareAndPolicy_4(hash_fn, compare_fn, value_compare_fn, policy_value)                        \
        MapInitWithValueCompareAndPolicy_5(hash_fn, compare_fn, value_compare_fn, policy_value, MisraScope)
    /// TAGS: Map, Init, DeepCopy, Copy
    ///
    #define MapInitWithDeepCopy(...) OVERLOAD(MapInitWithDeepCopy, __VA_ARGS__)
    #define MapInitWithDeepCopy_6(hash_fn, compare_fn, key_ci, key_cd, value_ci, value_cd)                                 \
        MapInitWithDeepCopy_7(hash_fn, compare_fn, key_ci, key_cd, value_ci, value_cd, MisraScope)
        )
    
    #define MapInitT(m, ...) OVERLOAD(MapInitT, m, __VA_ARGS__)
    #ifdef __cplusplus
    #    define MapInitT_3(m, hash_fn, compare_fn) (TYPE_OF(m) MapInit_3((hash_fn), (compare_fn), MisraScope))
    #endif
    
    #define MapInitWithDeepCopyT(m, ...) OVERLOAD(MapInitWithDeepCopyT, m, __VA_ARGS__)
    #ifdef __cplusplus
    #    define MapInitWithDeepCopyT_7(m, hash_fn, compare_fn, key_ci, key_cd, value_ci, value_cd)                         \
    ///
    bool proc_maps_load(ProcMaps *out, Allocator *alloc);
    #define ProcMapsLoad(...)          OVERLOAD(ProcMapsLoad, __VA_ARGS__)
    #define ProcMapsLoad_1(out)        proc_maps_load((out), MisraScope)
    #define ProcMapsLoad_2(out, alloc) proc_maps_load((out), ALLOCATOR_OF(alloc))
    /// TAGS: Sys, Backtrace, Unwind
    ///
    #define CaptureStackTrace(...)              OVERLOAD(CaptureStackTrace, __VA_ARGS__)
    #define CaptureStackTrace_3(out, max, skip) capture_stack_trace_raw((out), (max), (skip))
    #define CaptureStackTrace_2(out, skip)      capture_stack_trace_vec((out), (skip))
    /// TAGS: Sys, Backtrace, CFI, Unwind
    ///
    #    define CaptureStackTraceCfi(...)                   OVERLOAD(CaptureStackTraceCfi, __VA_ARGS__)
    #    define CaptureStackTraceCfi_4(out, max, skip, res) capture_stack_trace_cfi_raw((out), (max), (skip), (res))
    #    define CaptureStackTraceCfi_3(out, skip, res)      capture_stack_trace_cfi_vec((out), (skip), (res))
    /// TAGS: Sys, Backtrace, Format
    ///
    #define FormatStackTrace(...)                         OVERLOAD(FormatStackTrace, __VA_ARGS__)
    #define FormatStackTrace_4(out, frames, count, alloc) format_stack_trace_raw((out), (frames), (count), (alloc))
    #define FormatStackTrace_3(out, frames, alloc)        format_stack_trace_vec((out), (frames), (alloc))
    /// TAGS: Sys, Backtrace, Format
    ///
    #    define FormatStackTraceWith(...)                       OVERLOAD(FormatStackTraceWith, __VA_ARGS__)
    #    define FormatStackTraceWith_4(out, frames, count, res) format_stack_trace_with_raw((out), (frames), (count), (res))
    #    define FormatStackTraceWith_3(out, frames, res)        format_stack_trace_with_vec((out), (frames), (res))
        Proc proc_init(Zstr path, char **argv, char **envp, Allocator *alloc);
    
    #define ProcInit(...)                       OVERLOAD(ProcInit, __VA_ARGS__)
    #define ProcInit_3(path, argv, envp)        proc_init((path), (argv), (envp), MisraScope)
    #define ProcInit_4(path, argv, envp, alloc) proc_init((path), (argv), (envp), ALLOCATOR_OF(alloc))
    /// TAGS: Sys, MachO, Cache, Init, Lifecycle
    ///
    #define MachoCacheInit(...)         OVERLOAD(MachoCacheInit, __VA_ARGS__)
    #define MachoCacheInit_0()          MachoCacheInit_1(MisraScope)
    #define MachoCacheInit_1(alloc_ptr) ((MachoCache) {.allocator = ALLOCATOR_OF(alloc_ptr), .entries = VecInit_1(alloc_ptr)})
    ///
    DirContents dir_get_contents(Zstr path, Allocator *alloc);
    #define DirGetContents(...) OVERLOAD(DirGetContents, __VA_ARGS__)
    #define DirGetContents_1(path)                                                                                         \
        _Generic(                                                                                                          \
    ///
    Str socket_addr_format(const SocketAddr *addr, Allocator *alloc);
    #define SocketAddrFormat(...)           OVERLOAD(SocketAddrFormat, __VA_ARGS__)
    #define SocketAddrFormat_1(addr)        socket_addr_format((addr), MisraScope)
    #define SocketAddrFormat_2(addr, alloc) socket_addr_format((addr), ALLOCATOR_OF(alloc))
        ///
        bool dns_resolver_init(DnsResolver *out, Allocator *alloc);
    #define DnsResolverInit(...)          OVERLOAD(DnsResolverInit, __VA_ARGS__)
    #define DnsResolverInit_1(out)        dns_resolver_init((out), MisraScope)
    #define DnsResolverInit_2(out, alloc) dns_resolver_init((out), ALLOCATOR_OF(alloc))
        /// TAGS: Dns, Resolve, API
        ///
    #define DnsResolve(...) OVERLOAD(DnsResolve, __VA_ARGS__)
    #define DnsResolve_4(self, spec, kind, out)                                                                                                                                                                                                                                \
        _Generic((out), DnsAddrs *: _Generic((spec), Str *: dns_resolve_4_vec_str, Zstr: dns_resolve_4_vec_zstr, char *: dns_resolve_4_vec_zstr), SocketAddr *: _Generic((spec), Str *: dns_resolve_4_one_str, Zstr: dns_resolve_4_one_zstr, char *: dns_resolve_4_one_zstr))( \
    ///
    bool symbol_resolver_init(SymbolResolver *out, Allocator *alloc);
    #define SymbolResolverInit(...)          OVERLOAD(SymbolResolverInit, __VA_ARGS__)
    #define SymbolResolverInit_1(out)        symbol_resolver_init((out), MisraScope)
    #define SymbolResolverInit_2(out, alloc) symbol_resolver_init((out), ALLOCATOR_OF(alloc))
    /// TAGS: Sys, PDB, Cache, Init, Lifecycle
    ///
    #define PdbCacheInit(...)        OVERLOAD(PdbCacheInit, __VA_ARGS__)
    #define PdbCacheInit_0()         PdbCacheInit_1(MisraScope)
    #define PdbCacheInit_1(alloc_ptr) ((PdbCache) {.allocator = ALLOCATOR_OF(alloc_ptr), .entries = VecInit_1(alloc_ptr)})
    /// TAGS: KvConfig, Init, API
    ///
    #define KvConfigInit(...) OVERLOAD(KvConfigInit, __VA_ARGS__)
    #define KvConfigInit_0()  KvConfigInit_1(MisraScope)
    #define KvConfigInit_1(allocator_ptr)                                                                                  \
    ///
    bool pe_open(Pe *out, Zstr path, Allocator *alloc);
    #define PeOpen(...) OVERLOAD(PeOpen, __VA_ARGS__)
    #define PeOpen_2(out, path)                                                                                            \
        _Generic(                                                                                                          \
    ///
    bool pe_open_from_memory_copy(Pe *out, const u8 *data, size data_size, Allocator *alloc);
    #define PeOpenFromMemoryCopy(...)                    OVERLOAD(PeOpenFromMemoryCopy, __VA_ARGS__)
    #define PeOpenFromMemoryCopy_3(out, data, data_size) pe_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define PeOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                            \
    ///
    bool pdb_open(Pdb *out, Zstr path, Allocator *alloc);
    #define PdbOpen(...) OVERLOAD(PdbOpen, __VA_ARGS__)
    #define PdbOpen_2(out, path)                                                                                           \
        _Generic(                                                                                                          \
    ///
    bool pdb_open_from_memory_copy(Pdb *out, const u8 *data, size data_size, Allocator *alloc);
    #define PdbOpenFromMemoryCopy(...)                    OVERLOAD(PdbOpenFromMemoryCopy, __VA_ARGS__)
    #define PdbOpenFromMemoryCopy_3(out, data, data_size) pdb_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define PdbOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                           \
    ///
    bool dwarf_lines_build_from_elf(DwarfLines *out, const Elf *elf, Allocator *alloc);
    #define DwarfLinesBuildFromElf(...)               OVERLOAD(DwarfLinesBuildFromElf, __VA_ARGS__)
    #define DwarfLinesBuildFromElf_2(out, elf)        dwarf_lines_build_from_elf((out), (elf), MisraScope)
    #define DwarfLinesBuildFromElf_3(out, elf, alloc) dwarf_lines_build_from_elf((out), (elf), ALLOCATOR_OF(alloc))
    ///
    bool dwarf_cfi_build_from_elf(DwarfCfi *out, const Elf *elf, Allocator *alloc);
    #define DwarfCfiBuildFromElf(...)               OVERLOAD(DwarfCfiBuildFromElf, __VA_ARGS__)
    #define DwarfCfiBuildFromElf_2(out, elf)        dwarf_cfi_build_from_elf((out), (elf), MisraScope)
    #define DwarfCfiBuildFromElf_3(out, elf, alloc) dwarf_cfi_build_from_elf((out), (elf), ALLOCATOR_OF(alloc))
    ///
    bool dwarf_functions_build_from_elf(DwarfFunctions *out, const Elf *elf, Allocator *alloc);
    #define DwarfFunctionsBuildFromElf(...)               OVERLOAD(DwarfFunctionsBuildFromElf, __VA_ARGS__)
    #define DwarfFunctionsBuildFromElf_2(out, elf)        dwarf_functions_build_from_elf((out), (elf), MisraScope)
    #define DwarfFunctionsBuildFromElf_3(out, elf, alloc) dwarf_functions_build_from_elf((out), (elf), ALLOCATOR_OF(alloc))
    /// TAGS: Http, Header, Init
    ///
    #define HttpHeaderInit(...)         OVERLOAD(HttpHeaderInit, __VA_ARGS__)
    #define HttpHeaderInit_0()          HttpHeaderInit_1(MisraScope)
    #define HttpHeaderInit_1(alloc_ptr) ((HttpHeader) {.key = StrInit_1(alloc_ptr), .value = StrInit_1(alloc_ptr)})
    /// TAGS: Http, Request, Init
    ///
    #define HttpRequestInit(...) OVERLOAD(HttpRequestInit, __VA_ARGS__)
    #define HttpRequestInit_0()  HttpRequestInit_1(MisraScope)
    #define HttpRequestInit_1(alloc_ptr)                                                                                   \
    /// TAGS: Http, Response, Init
    ///
    #define HttpResponseInit(...) OVERLOAD(HttpResponseInit, __VA_ARGS__)
    #define HttpResponseInit_0()  HttpResponseInit_1(MisraScope)
    #define HttpResponseInit_1(alloc_ptr)                                                                                  \
    ///
    Str http_response_serialize(const HttpResponse *response, Allocator *alloc);
    #define HttpResponseSerialize(...)               OVERLOAD(HttpResponseSerialize, __VA_ARGS__)
    #define HttpResponseSerialize_1(response)        http_response_serialize((response), MisraScope)
    #define HttpResponseSerialize_2(response, alloc) http_response_serialize((response), ALLOCATOR_OF(alloc))
    ///
    bool elf_open(Elf *out, Zstr path, Allocator *alloc);
    #define ElfOpen(...) OVERLOAD(ElfOpen, __VA_ARGS__)
    #define ElfOpen_2(out, path)                                                                                           \
        _Generic(                                                                                                          \
    ///
    bool elf_open_from_memory_copy(Elf *out, const u8 *data, size data_size, Allocator *alloc);
    #define ElfOpenFromMemoryCopy(...)                    OVERLOAD(ElfOpenFromMemoryCopy, __VA_ARGS__)
    #define ElfOpenFromMemoryCopy_3(out, data, data_size) elf_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define ElfOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                           \
    ///
    bool macho_open(Macho *out, Zstr path, Allocator *alloc);
    #define MachoOpen(...) OVERLOAD(MachoOpen, __VA_ARGS__)
    #define MachoOpen_2(out, path)                                                                                         \
        _Generic(                                                                                                          \
    ///
    bool macho_open_from_memory_copy(Macho *out, const u8 *data, size data_size, Allocator *alloc);
    #define MachoOpenFromMemoryCopy(...) OVERLOAD(MachoOpenFromMemoryCopy, __VA_ARGS__)
    #define MachoOpenFromMemoryCopy_3(out, data, data_size)                                                                \
        macho_open_from_memory_copy((out), (data), (data_size), MisraScope)
Last updated on