#pragma once #include #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// template class TErasedStorage; //////////////////////////////////////////////////////////////////////////////// namespace NDetail { template struct TIsErasedStorage : public std::false_type { }; template struct TIsErasedStorage> : public std::true_type { }; } // namespace NDetail //////////////////////////////////////////////////////////////////////////////// template concept CTriviallyErasable = std::default_initializable && std::is_trivially_destructible_v && std::is_trivially_copyable_v && (sizeof(T) <= ErasedStorageMaxByteSize) && (alignof(T) <= ErasedStorageMaxByteSize) && !std::is_reference_v && !NDetail::TIsErasedStorage::value; //////////////////////////////////////////////////////////////////////////////// // This class does not call dtor of erased object // thus we require trivial destructability. template class TErasedStorage { public: static constexpr size_t ByteSize = MaxByteSize; template TDecayedConcrete> explicit TErasedStorage(TDecayedConcrete concrete) noexcept; TErasedStorage(const TErasedStorage& other) = default; TErasedStorage& operator=(const TErasedStorage& other) = default; template TDecayedConcrete> TDecayedConcrete& AsConcrete() & noexcept; template TDecayedConcrete> const TDecayedConcrete& AsConcrete() const & noexcept; template TDecayedConcrete> TDecayedConcrete&& AsConcrete() && noexcept; bool operator==(const TErasedStorage& other) const = default; private: // NB(arkady-e1ppa): aligned_storage is deprecated. alignas(MaxByteSize) std::byte Bytes_[MaxByteSize]; }; //////////////////////////////////////////////////////////////////////////////// } // namespace NYT #define ERASED_STORAGE_INL_H_ #include "erased_storage-inl.h" #undef ERASED_STORAGE_INL_H_