AlignedData.cppm 764 B

1234567891011121314151617181920212223242526272829303132
  1. export module Core.AlignedData;
  2. export import Core.Types;
  3. export namespace Core {
  4. template<size_t SIZE, size_t ALIGNMENT>
  5. class alignas(ALIGNMENT) AlignedData final {
  6. char buffer[SIZE] = {};
  7. public:
  8. template<typename T>
  9. constexpr T* as() noexcept {
  10. return reinterpret_cast<T*>(this);
  11. }
  12. template<typename T>
  13. constexpr const T* as() const noexcept {
  14. return reinterpret_cast<T*>(this);
  15. }
  16. static consteval size_t getSize() noexcept {
  17. return SIZE;
  18. }
  19. static consteval size_t getAlignment() noexcept {
  20. return ALIGNMENT;
  21. }
  22. };
  23. template<typename T>
  24. using AlignedType = AlignedData<sizeof(T), alignof(T)>;
  25. }