From 5f2c7110a1880fde47317cb920db978d6995638f Mon Sep 17 00:00:00 2001 From: aura Date: Sun, 26 Jul 2026 02:58:07 +0200 Subject: list utils --- src/util/allocator.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/util/allocator.h') diff --git a/src/util/allocator.h b/src/util/allocator.h index 623d227..d97952d 100644 --- a/src/util/allocator.h +++ b/src/util/allocator.h @@ -2,6 +2,7 @@ #include #include +#include #include "callback.h" template @@ -160,6 +161,9 @@ struct LIST { if( capacity >= count ) return; + if( count < size ) + return; + T* newblock = (T*)malloc( count * sizeof( T ) ); memset( newblock, 0, count * sizeof( T ) ); if( data ) { @@ -203,6 +207,16 @@ struct LIST { return &data[size - 1]; } + template < typename ... IT > + void emplace( const T& item, IT&& ... items ) { + constexpr U32 nsize = sizeof...( IT ) + 1; + if( size + nsize > capacity ) + reserve( size + nsize ); + + emplace( item ); + emplace( ( items )... ); + } + T* push( const T& item ) { if( capacity == size ) grow(); @@ -211,6 +225,16 @@ struct LIST { return &data[size - 1]; } + template < typename ... IT > + void push( const T& item, IT&& ... items ) { + constexpr U32 nsize = sizeof...( IT ) + 1; + if( size + nsize > capacity ) + reserve( size + nsize ); + + push( item ); + push( ( items )... ); + } + void resize( U32 size ) { if( size > capacity ) reserve( size * 2 ); -- cgit v1.2.3