C Collections

citerators · Section 3

ccol_iter_key_ptr

ccol_iter_key_ptr - get a typed const pointer to the current key

C Collections (libccollections, -lccollections)

#include <ccollections/citerators.h>   /* or any container header */
 
const KeyT *ccol_iter_key_ptr(it);

ccol_iter_key_ptr returns a typed const pointer to the key of the
element that the iterator is on.
 
For a cvec iterator the key is the element's index, a size_t. For a chmap
or a cbmap iterator it is the real map key. A char-pointer key comes back
as a (char *const *) into the map's internal storage, and the string it
points to belongs to the map. Every other key type comes back as a
direct typed pointer.

it   Iterator variable that ccol_iter_declare() declares, or an iterator
     inside ccol_for_each().

A const KeyT* to the current key. Do not free or change the value
through this pointer.

The pointer is valid only while the iterator is alive and the container
does not change.
The macro uses a GNU C statement expression, so it needs GCC or Clang.

ccol_iter_val_ptr(3), ccol_iter_declare(3)