#ifndef CUTES_LIST_H #define CUTES_LIST_H #include "stddef.h" typedef struct List List; struct List { void* data; size_t cap; size_t len; size_t element_size; }; extern List list_init(size_t element_size); extern List list_with_len(size_t element_size, size_t len); extern List list_copy(const List* source); extern void list_empty(List* list); extern void list_reserve(List* self, size_t at_least); extern void list_set_len(List* self, size_t len); extern void* list_at(List* list, size_t at); extern void* list_at_unchecked(List* self, size_t at); extern size_t list_add(List* self, void* item); extern void list_insert(List* self, void* item, size_t at); extern void list_erase(List* self, size_t at); extern void* list_iterator_begin(List* self); extern void* list_iterator_end(List* self); extern size_t list_contains(List* self, void* query); #define list_from_type(T) list_init(sizeof(T)) #define list_from_type_with_len(T, __len) list_with_len(sizeof(T), __len) #define list_foreach(T, iter, list) for(T iter = list_iterator_begin(list); iter != (T)list_iterator_end(list); ++iter) #define list_at_as(T, __list, __i) ((T*)(list_at(__list, __i))) #define list_iterator_begin_as(T, __list) ((T*)(list_iterator_begin(__list))) #endif // !CUTES_LIST_H