citerators · Section 3
ccol_iter_declare
NAME
ccol_iter_declare - declare a typed iterator variable with RAII cleanup
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/citerators.h> /* or any container header */ ccol_iter_declare(container, it);
DESCRIPTION
ccol_iter_declare declares a cmap_iterator pointer named it that carries the type information of container. The declaration has __attribute__((cleanup)), so the iterator is destroyed at the end of its scope and you don't need an explicit ccol_iter_destroy() call. It also declares two hidden companion type variables. Those are what let ccol_iter_key_ptr() and ccol_iter_val_ptr() return pointers of the right type for container.
PARAMETERS
container Container variable, declared beforehand with a *_declare or
*_construct macro. It must be a cvec, a chmap or a cbmap.
it Name for the iterator variable.
NOTES
container must be in scope, and its companion type variables must be visible too, in the same scope or in a parent one. The macro uses __attribute__((cleanup)), so it needs GCC or Clang. When a loop leaves early, the iterator stays live until the end of the scope. You can destroy the container before that point, since the cleanup frees the iterator without reading the container, but do not advance or dereference the iterator once its container is gone.
EXAMPLES
ccol_iter_declare(my_map, it); for (it = ccol_begin(my_map); it != NULL; it = ccol_iter_next(it)) { printf("%d\n", *ccol_iter_val_ptr(it)); }
SEE ALSO
ccol_begin(3), ccol_iter_next(3), ccol_for_each(3), ccol_iter_destroy(3)