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 ++++++++++++++++++++++++ src/util/callback.h | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) 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 ); diff --git a/src/util/callback.h b/src/util/callback.h index a2c9477..ef4e815 100644 --- a/src/util/callback.h +++ b/src/util/callback.h @@ -1,16 +1,17 @@ #pragma once #include "typedef.h" +template struct __strip_ref { using type = T; }; +template struct __strip_ref { using type = T; }; +template struct __strip_ref { using type = T; }; +template struct __strip_ref { using type = R(*)(A...); }; +template struct __strip_ref { using type = R(*)(A...); }; + template struct FN; // voodoo template struct FN { - template struct __strip_ref { using type = T; }; - template struct __strip_ref { using type = T; }; - template struct __strip_ref { using type = T; }; - template struct __strip_ref { using type = R(*)(A...); }; - template struct __strip_ref { using type = R(*)(A...); }; static const unsigned int BUF_SIZE = 32; -- cgit v1.2.3