erased_storage-inl.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef ERASED_STORAGE_INL_H_
  2. #error "Direct inclusion of this file is not allowed, include erased_storage.h"
  3. // For the sake of sane code completion.
  4. #include "erased_storage.h"
  5. #endif
  6. namespace NYT {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. template <CTriviallyErasable TDecayedConcrete>
  9. TErasedStorage::TErasedStorage(TDecayedConcrete concrete) noexcept
  10. {
  11. std::construct_at(
  12. &AsConcrete<TDecayedConcrete>(),
  13. concrete);
  14. }
  15. template <CTriviallyErasable TDecayedConcrete>
  16. TDecayedConcrete& TErasedStorage::AsConcrete() & noexcept
  17. {
  18. using TPtr = TDecayedConcrete*;
  19. return *std::launder(reinterpret_cast<TPtr>(&Bytes_));
  20. }
  21. template <CTriviallyErasable TDecayedConcrete>
  22. const TDecayedConcrete& TErasedStorage::AsConcrete() const & noexcept
  23. {
  24. using TPtr = const TDecayedConcrete*;
  25. return *std::launder(reinterpret_cast<TPtr>(&Bytes_));
  26. }
  27. template <CTriviallyErasable TDecayedConcrete>
  28. TDecayedConcrete&& TErasedStorage::AsConcrete() && noexcept
  29. {
  30. using TPtr = TDecayedConcrete*;
  31. return std::move(*std::launder(reinterpret_cast<TPtr>(&Bytes_)));
  32. }
  33. ////////////////////////////////////////////////////////////////////////////////
  34. } // namespace NYT