#ifndef CORE_ALIGNED_DATA_HPP #define CORE_ALIGNED_DATA_HPP #define alignmentof(type) __alignof__(type) #define 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(alignmentof(var) == alignmentof(type), \ "aligned data alignment missmatch"); namespace Core { template class alignas(ALIGNMENT) AlignedData { static_assert(SIZE > 0, "size must be positive"); char buffer[static_cast(SIZE)] = {}; public: template T* as() { return reinterpret_cast(this); } template 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