kolibrios-fun/programs/develop/clink/cvec
..
cvec.h
LICENSE
README.md

cvec - partial std::vector implementation in C.

Partial implementation of std::vector

Member functions table:

Status Name Function or reason if not implemented
✔️ (constructor) new
✔️ (destructor) free
✔️ operator= assign_other
✔️ assign assign_fill, assign_range
get_allocator No allocator objects in the language
✔️ at at
✔️ operator[] []
✔️ front front, front_p
✔️ back back, back_p
✔️ data data
✔️ begin begin
✔️ cbegin cbegin
✔️ end end
✔️ cend cend
rbegin No reverse iterators in the language
crbegin No reverse iterators in the language
rend No reverse iterators in the language
crend No reverse iterators in the language
✔️ empty empty
✔️ size size
✔️ max_size max_size
✔️ reserve reserve
✔️ capacity capacity
✔️ shrink_to_fit shrink_to_fit
✔️ clear clear
✔️ insert insert, insert_it
emplace I know no way to preserve the original signature
✔️ erase erase
✔️ push_back push_back
emplace_back I know no way to preserve the original signature
✔️ pop_back pop_back
✔️ resize resize
swap Would have n complexity in this implementation

Easy to use

To use the std::vector implementation for specified type they should be declared as follows:

#define CVEC_TYPE TypeOfVectorElement
#include "cvec.h"

// ...

    TypeOfVectorElement *vec = cvec_TypeOfVectorElement_new(128);
    
    cvec_TypeOfVectorElement_push_back(&vec, value);

Also somewhere in the project the functinos should be instantiated as follows:

#define CVEC_TYPE TypeOfVectorElement
#define CVEC_INST
#include "cvec.h"

Allows using of custom allocators.

#define CVEC_TYPE pchar
#define CVEC_INST
#define CVEC_MALLOC custom_malloc
#define CVEC_REALLOC custom_realloc
#define CVEC_FREE custom_free
#include "cvec.h"

Allows handling of exceptional cases.

#define CVEC_TYPE pchar
#define CVEC_INST
// Set Out Of Bounds handler
#define CVEC_OOBH(funcname, vec, index) printf("Out of bounds in %s (vec = %p, i = %d)", funcname, vec, index); abort();
#include "cvec.h"

Has no fixed dependencies

Every function it uses may be overridden. More information about dependencies in cvec.h.