#pragma once #include typedef struct { const void *ctx; void *(*alloc)(const void *ctx, size_t elem, size_t nelems, size_t alignment); void (*free)(const void *ctx, void *ptr, size_t elem, size_t nelems, size_t alignment); #ifdef __cplusplus template [[nodiscard]] T *allocate(size_t n) { return static_cast(this->alloc(this->ctx, sizeof(T), n, _Alignof(T))); } template [[nodiscard]] void deallocate(T *p, size_t n) { this->free(this->ctx, static_cast(p), sizeof(T), n, _Alignof(T)); } #endif } zig_allocator;