C Collections

citerators · Section 3

ccol_iter_val_ptr

ccol_iter_val_ptr - get a typed pointer to the current value

C Collections (libccollections, -lccollections)

#include <ccollections/citerators.h>   /* or any container header */
 
ValT *ccol_iter_val_ptr(it);            /* ValT const * for a char pointer */

ccol_iter_val_ptr returns a typed pointer to the value of the element
that the iterator is on. Writing through it changes the element in the
container.
 
When the value type is a character pointer, the target is const
qualified. You can read the stored string and edit its bytes in place
within the stored length, but you do not replace the string. The pointer
names the map's own accessor slot, whose companion size field describes
the string the slot points at. If you store a pointer there that the map
did not allocate and did not size, that size describes a different
string and the next read of the element runs past the end of the new
one. To store a different string, use the insert operation of the owning
container. For every other value type the pointer names the element
itself and you can write through it.

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

A ValT* to the current element, or a ValT const* when ValT is a
character 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_key_ptr(3), ccol_iter_declare(3)