#ifndef CORE_ALIGNED_DATA_HPP #define CORE_ALIGNED_DATA_HPP #define CORE_ASSERT_ALIGNED_DATA(var, type) \ static_assert(sizeof(var) == sizeof(type), "aligned data size missmatch"); \ static_assert(var.getSize() >= var.getAlignment(), "size >= alignment"); \ static_assert(alignof(decltype(var)) == alignof(type), \ "aligned data alignment missmatch"); namespace Core { template class alignas(ALIGNMENT) AlignedData final { static_assert(SIZE > 0, "size must be positive"); char buffer[static_cast(SIZE)] = {}; public: template constexpr T* as() { return reinterpret_cast(this); } template constexpr const T* as() const { return reinterpret_cast(this); } static consteval int getSize() { return SIZE; } static consteval int getAlignment() { return ALIGNMENT; } }; template using AlignedType = AlignedData; } #endif