44#include "attributes.h"
46#define ARRAY_SENTINEL 0x15bada55
57 char alignas( max_align_t )
_array[];
60void *_array_create_helper(
size_t e_size,
size_t initial_size );
61void *_array_grow_helper(
void **a,
size_t e_size );
62void _array_resize_helper(
void **a,
size_t e_size,
size_t new_size );
63void _array_erase_helper(
void **a,
size_t e_size,
void *first,
void *last );
64void _array_shrink_helper(
void **a,
size_t e_size );
65void _array_free_helper(
void *a );
66void *_array_copy_helper(
size_t e_size,
void *a );
76 assert(
"NULL array!" && ( a != NULL ) );
81 assert(
"Sentinel not found. Use array_create() to create the array." &&
93#define array_create( basic_type ) \
94 ( (basic_type *)( _array_create_helper( sizeof( basic_type ), 1 ) ) )
102#define array_create_size( basic_type, capacity ) \
103 ( (basic_type *)( _array_create_helper( sizeof( basic_type ), capacity ) ) )
113#define array_resize( ptr_array, new_size ) \
114 ( _array_resize_helper( (void **)( ptr_array ), \
115 sizeof( ( ptr_array )[0][0] ), new_size ) )
122#define array_grow( ptr_array ) \
123 ( *(__typeof__( ( ptr_array )[0] ))_array_grow_helper( \
124 (void **)( ptr_array ), \
125 sizeof( ( ptr_array )[0][0] ) ) )
134#define array_push_back( ptr_array, element ) \
136 array_grow( ptr_array ) = element; \
148#define array_erase( ptr_array, first, last ) \
149 ( _array_erase_helper( (void **)( ptr_array ), \
150 sizeof( ( ptr_array )[0][0] ), (void *)( first ), \
160#define array_shrink( ptr_array ) \
161 ( _array_shrink_helper( (void **)( ptr_array ), \
162 sizeof( ( ptr_array )[0][0] ) ) )
170#define array_free( ptr_array ) _array_free_helper( (void *)( ptr_array ) )
179ALWAYS_INLINE
static inline int array_size(
const void *array )
187 assert(
"Sentinel not found. Use array_create() to create the array." &&
199#define array_reserved( array ) ( _array_private_container( array )->_reserved )
206#define array_begin( array ) ( array )
214#define array_end( array ) ( ( array ) + array_size( array ) )
221#define array_front( ptr_array ) ( *array_begin( ptr_array ) )
228#define array_back( ptr_array ) ( *( array_end( ptr_array ) - 1 ) )
230#define array_copy( basic_type, ptr_array ) \
231 ( (basic_type *)( _array_copy_helper( sizeof( basic_type ), \
232 (void *)( ptr_array ) ) ) )
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
static _private_container * _array_private_container(void *a)
Gets the container of an array.
Private container type for the arrays.