citerators · Section 3
ccol_begin
NAME
ccol_begin - begin iteration over any supported container
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/citerators.h> /* or any container header */ cmap_iterator *ccol_begin(container);
DESCRIPTION
ccol_begin returns an iterator on the first element of container. The begin_iter function to call is picked at compile time with _Generic on the type of container. The supported types are cvec, chmap and cbmap, and a container of any other type (a void * included) is a compile error. An empty container gives NULL and no error. A NULL container handle iterates as an empty container, so it gives NULL and no error as well. If an allocation fails, the macro calls ccol__fatal_err().
PARAMETERS
container A cvec, chmap or cbmap variable.
RETURN VALUE
A cmap_iterator* on the first element, or NULL when the container is empty.
NOTES
Declare the iterator with ccol_iter_declare(container, it) before you call ccol_begin in a for loop, since that declaration is what gives you typed accessors for it.
EXAMPLES
ccol_iter_declare(vec, it); for (it = ccol_begin(vec); it != NULL; it = ccol_iter_next(it)) { printf("[%zu] = %d\n", *ccol_iter_key_ptr(it), *ccol_iter_val_ptr(it)); }
SEE ALSO
ccol_iter_declare(3), ccol_iter_next(3), ccol_for_each(3), ccol_end(3)