diff options
| author | aura <nw@moneybot.cc> | 2026-07-26 02:58:07 +0200 |
|---|---|---|
| committer | aura <nw@moneybot.cc> | 2026-07-26 02:58:07 +0200 |
| commit | 5f2c7110a1880fde47317cb920db978d6995638f (patch) | |
| tree | c8ca6674194d7a522408af8cfe5b2f96e2e68f84 | |
| parent | 2cd0e46e450c89db5e7eac1a02e28000256db1d8 (diff) | |
list utils
| -rw-r--r-- | src/util/allocator.h | 24 | ||||
| -rw-r--r-- | 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 <stdlib.h> #include <string.h> +#include <utility> #include "callback.h" template <typename T> @@ -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 <typename T> struct __strip_ref { using type = T; }; +template <typename T> struct __strip_ref<T&> { using type = T; }; +template <typename T> struct __strip_ref<T&&> { using type = T; }; +template <typename R, typename... A> struct __strip_ref<R(A...)> { using type = R(*)(A...); }; +template <typename R, typename... A> struct __strip_ref<R(&)(A...)> { using type = R(*)(A...); }; + template <typename T> struct FN; // voodoo template <typename RET, typename... ARGS> struct FN<RET(ARGS...)> { - template <typename T> struct __strip_ref { using type = T; }; - template <typename T> struct __strip_ref<T&> { using type = T; }; - template <typename T> struct __strip_ref<T&&> { using type = T; }; - template <typename R, typename... A> struct __strip_ref<R(A...)> { using type = R(*)(A...); }; - template <typename R, typename... A> struct __strip_ref<R(&)(A...)> { using type = R(*)(A...); }; static const unsigned int BUF_SIZE = 32; |
