diff options
Diffstat (limited to 'archive/src/std/containers/stack_array.h')
-rw-r--r-- | archive/src/std/containers/stack_array.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/archive/src/std/containers/stack_array.h b/archive/src/std/containers/stack_array.h new file mode 100644 index 0000000..d2b6bdd --- /dev/null +++ b/archive/src/std/containers/stack_array.h @@ -0,0 +1,19 @@ +#pragma once +#include <stdbool.h> + +// Defines "_sarray" types + +#define TYPED_STACK_ARRAY(T, Name, Len) \ + typedef struct Name##_sarray { \ + T items[ Len ]; \ + size_t len; \ + } Name##_sarray; \ + Name##_sarray Name##_sarray_create() { \ + Name##_sarray arr = { .len = 0 }; \ + return arr; \ + } \ + bool Name##_sarray_push(Name##_sarray* arr, T item) { \ + if (arr->len == Len) { return false; }\ + arr->items[arr->len++] = item;\ + return true;\ + } |