cvector · Section 3
cvec_at
NAME
cvec_at - access element at index (type-inferred, returns reference)
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cvector.h> element_ref = cvec_at(v, index);
DESCRIPTION
Type-inferred wrapper for cvector_at(). It gives a reference to the element, already of the right type, rather than a pointer, so you can use it as an lvalue in an assignment.
PARAMETERS
v Vector to access index Zero-based index of the element
RETURN VALUE
A reference to the element at the index.
NOTES
What you get is a reference, not a pointer, and you can put it on the left side of an assignment. index is evaluated exactly once, so an expression with a side effect, for example cvec_at(v, i++), is safe to pass. An index that is out of bounds stops the program with ccol__fatal_err(). If you'd rather get NULL for such an index, use cvec_at_ptr.
EXAMPLES
cvec_construct(vec, int); cvec_push(vec, 42); int val = cvec_at(vec, 0); // val == 42 cvec_at(vec, 0) = 5; // the first element is now 5 cvec_destroy(vec);