summaryrefslogtreecommitdiff
path: root/src/util/allocator.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/allocator.h')
-rw-r--r--src/util/allocator.h24
1 files changed, 24 insertions, 0 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 );