Add ability to fill array with capacity

This commit is contained in:
2025-12-28 18:31:49 +00:00
parent a065dfb573
commit 1cbb148a1f
3 changed files with 18 additions and 12 deletions

View File

@@ -43,13 +43,13 @@ BEGIN_C_LINKAGE
items, \
}; \
}())
#define wapp_array_with_capacity(ELEM_TYPE, ARRAY_TYPE, CAPACITY) ([&]() { \
#define wapp_array_with_capacity(ELEM_TYPE, ARRAY_TYPE, CAPACITY, FILL) ([&]() { \
wapp_persist ELEM_TYPE items[sizeof(ELEM_TYPE) == sizeof(*((ARRAY_TYPE{}).items)) ? \
CAPACITY : -1] = {}; \
\
return ARRAY_TYPE{ \
WAPP_ARRAY_MAGIC, \
0, \
FILL ? CAPACITY : 0, \
CAPACITY, \
sizeof(ELEM_TYPE), \
items, \
@@ -74,10 +74,10 @@ BEGIN_C_LINKAGE
_calc_array_capacity(ELEM_TYPE, __VA_ARGS__) : \
-1]){__VA_ARGS__} \
})
#define wapp_array_with_capacity(ELEM_TYPE, ARRAY_TYPE, CAPACITY) \
#define wapp_array_with_capacity(ELEM_TYPE, ARRAY_TYPE, CAPACITY, FILL) \
((ARRAY_TYPE){ \
.magic = WAPP_ARRAY_MAGIC, \
.count = 0, \
.count = FILL ? CAPACITY : 0, \
.capacity = CAPACITY, \
.item_size = sizeof(ELEM_TYPE), \
.items = (ELEM_TYPE[sizeof(ELEM_TYPE) == sizeof(*((ARRAY_TYPE){0}.items)) ? \