C Collections

cvector · Section 3

cvec_pop

cvec_pop - pop an element from the vector (type-inferred)

C Collections (libccollections, -lccollections)

#include <ccollections/cvector.h>
 
value = cvec_pop(v);

Type-inferred wrapper for cvector_pop_back() that gives the popped element
as a value and calls ccol__fatal_err() when the pop fails.

v    Vector to pop from

The value of the popped element.

A failure stops the program. The macro gives a value, not a pointer, and
it uses the GNU C statement expression extension.
 
A vector whose element type is an array, such as char[32], is refused at
compile time, because C can't give back an array as a value. Pop such an
element into a buffer of the element type with cvector_pop_back().

cvec_construct(vec, int);
cvec_push(vec, 42);
int val = cvec_pop(vec);  // val == 42
cvec_destroy(vec);

cvector_pop_back(3), cvec_push(3)