allow any_t buffered (threads!!)

v1
Brett 2024-03-22 18:56:44 -04:00
parent 16641a27cb
commit 2dd44ca6e7
2 changed files with 28 additions and 1 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)
include(cmake/color.cmake)
set(BLT_VERSION 0.15.2)
set(BLT_VERSION 0.15.3)
set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT)

View File

@ -17,6 +17,7 @@
*/
#include <cstring>
#ifndef BLT_ANY_H
#define BLT_ANY_H
@ -158,6 +159,32 @@ namespace blt::unsafe
}
};
class buffer_any_t
{
private:
blt::u8* _data;
public:
explicit buffer_any_t(blt::u8* data): _data(data)
{}
template<typename T>
buffer_any_t& set(const T& t)
{
static_assert(std::is_trivially_copyable_v<T> && "Type must be trivially copyable");
std::memcpy(_data, &t, sizeof(t));
return *this;
}
template<typename T>
T any_cast()
{
static_assert(std::is_trivially_copyable_v<T> && "Type must be trivially copyable");
T t;
std::memcpy(&t, _data, sizeof(T));
return t;
}
};
template<blt::size_t SIZE>
class any_t_base
{