C Collections

cvector · Section 3

cvec_construct

cvec_construct - type-inferred vector construction

C Collections (libccollections, -lccollections)

#include <ccollections/cvector.h>
 
cvec_construct(vec_name, type);

Type-inferred macro that creates a vector and works out the element size
from the type. It also makes a type marker variable, which tells
the other type-dispatching macros the declared element type wherever you
call them.

vec_name  Name of the vector variable to create
type      Element type, for example int, double or struct foo
          Any type name works, a function pointer type such
          as void (*)(int) and an array type such as int[4]
          included. For an array element type, give
          cvec_push(3) an array or a string literal, whose
          bytes the macro copies into the element

The macro stops the program when an allocation fails.
 
The hidden type marker variable that it makes is read by the other
type-dispatching macros, and cvec_redeclare(3) makes it again in another
scope.
 
It is equivalent to cvector_create(sizeof(type), &err) plus the error
handling.

cvec_construct(my_vec, int);
cvec_push(my_vec, 42);
cvec_destroy(my_vec);

cvec_construct_scoped(3), cvector_create(3)