ptr stuff seems to wrok

v2
Brett 2025-01-16 19:33:12 -05:00
parent 2e6abb8013
commit 41c6dea002
3 changed files with 27 additions and 2 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake)
set(BLT_VERSION 3.0.0)
set(BLT_VERSION 3.0.1)
set(BLT_TARGET BLT)

View File

@ -146,9 +146,34 @@ namespace blt::mem
struct pointer_storage
{
static_assert(sizeof(Storage) * CHAR_BIT <= 16, "Storage type max size is 16 bits");
static_assert(std::is_trivially_copyable_v<Storage>, "Storage type must be trivially copyable!");
static_assert(alignof(Storage) <= 2, "Storage type must have an alignment of 2 or less!");
explicit pointer_storage(Ptr* ptr): ptr(ptr)
{
new (reinterpret_cast<char*>(&this->ptr) + 6) Storage{};
}
explicit pointer_storage(Ptr* ptr, const Storage& storage): ptr(ptr)
{
new (reinterpret_cast<char*>(&this->ptr) + 6) Storage{storage};
}
explicit pointer_storage(Ptr* ptr, Storage&& storage): ptr(ptr)
{
new (reinterpret_cast<char*>(&this->ptr) + 6) Storage{std::move(storage)};
}
Storage& storage()
{
auto offset_ptr = reinterpret_cast<char*>(&this->ptr) + 6;
return *std::launder(reinterpret_cast<Storage*>(offset_ptr));
}
const Storage& storage() const
{
const auto offset_ptr = reinterpret_cast<char const*>(&this->ptr) + 6;
return *std::launder(reinterpret_cast<Storage const*>(offset_ptr));
}
Ptr* get()

@ -1 +1 @@
Subproject commit 8a889d3699b3c09ade435641fb034427f3fd12b6
Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b