diff options
author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-07-18 21:33:50 +0300 |
---|---|---|
committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-07-18 21:33:50 +0300 |
commit | 94b767679fc68c51aa0c80bdada35b9978989199 (patch) | |
tree | 711af40c89140a9add7db30cf6a81861a3df1013 /test/vec.h | |
parent | 1564f79cfc7d790e15298d28f52b4c5c216ce9e5 (diff) | |
download | ngc-94b767679fc68c51aa0c80bdada35b9978989199.tar.gz ngc-94b767679fc68c51aa0c80bdada35b9978989199.zip |
add supertemplate handling
Diffstat (limited to 'test/vec.h')
-rw-r--r-- | test/vec.h | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/test/vec.h b/test/vec.h deleted file mode 100644 index 810e663..0000000 --- a/test/vec.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef VEC_H -#define VEC_H - -#include <stddef.h> -#include <assert.h> -#include <stdlib.h> - -typedef any {}; - -typedef vec[any type]() { - struct <> { - size_t n; - size_t s; - type *buf; - }; - - static inline struct <> <>create() - { - return (struct <>){ - .n = 0, - .s = 0, - .buf = NULL - }; - } - - static inline void <>append(struct <> *v, type n) - { - v->n++; - if (v->n > v->s) { - v->s = v->s == 0 ? 1 : 2 * v->s; - v->buf = realloc(v->buf, v->s * sizeof(type)); - } - - v->buf[v->n - 1] = n; - } - - static inline type *<>at(struct <> *v, size_t i) - { - assert(i < v->n); - return &v->buf[i]; - } - - static inline void <>destroy(struct <> *v) - { - free(v->buf); - } -} - -#endif /* VEC_H */ |