Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

29 rader
699 B

  1. #pragma once
  2. #include <ecs/config.h>
  3. #include <ecs/core/mp/core/copy_qualifiers.h>
  4. beg_namespace_ecs_core_utils
  5. {
  6. template <typename T, typename T_storage>
  7. inline constexpr decltype(auto) storage_cast(T_storage* storage) noexcept
  8. {
  9. static_assert(
  10. sizeof(T_storage) >= sizeof(T),
  11. "`T_storage` is not big enough for `T`.");
  12. static_assert(
  13. alignof(T_storage) >= alignof(T),
  14. "`T_storage` is not properly aligned for `T`.");
  15. assert(storage != nullptr);
  16. using return_type = mp::copy_cv_qualifiers<T, T_storage>;
  17. return reinterpret_cast<return_type*>(storage);
  18. }
  19. }
  20. end_namespace_ecs_core_utils