AlignedData.cppm 730 B

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