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