summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/allocator.h24
-rw-r--r--src/util/callback.h11
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;