C Container Collection (CCC)
Loading...
Searching...
No Matches
CCC_Key_comparator_arguments Struct Reference

A key comparison helper to avoid argument swapping. More...

#include <types.h>

Detailed Description

A key comparison helper to avoid argument swapping.

The key is considered the left hand side of the operation if three-way comparison is needed. Note a comparison is taking place between the key on the left hand side and the complete user type on the right hand side. This means the right hand side will need to manually access its key field.

int const *const key_left = order.key_left;
struct Key_val const *const type_right = order.type_right;
return (*key_left > type_right->key) - (*key_left < type_right->key);
void const *const type_right
Definition: types.h:497
void const *const key_left
Definition: types.h:495

Notice that the user type must access its key field of its struct. Comparison must happen this way to support searching by key in associative containers rather than by entire user struct. Only needing to provide a key can save significant memory for a search depending on the size of the user type.

The pointers are const to bind the key and type closely with their context, if context is provided. Because container code is providing the user reference to the key and type type it currently stores, it is critical the user does not accidentally move or misuse the pointer to jeopardize container invariants.

Data Fields

void const *const key_left
 
void const *const type_right
 
void *const context
 

Field Documentation

◆ context

void* const CCC_Key_comparator_arguments::context

A reference to context for this key comparison.

◆ key_left

void const* const CCC_Key_comparator_arguments::key_left

Key matching the key field of the provided type to the container.

◆ type_right

void const* const CCC_Key_comparator_arguments::type_right

The complete user type stored in the container.


The documentation for this struct was generated from the following file: