aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/leaky_singleton-inl.h
blob: 932747c9213b0c5954a6aca319f008c7f86698bd (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
#ifndef LEAKY_SINGLETON_INL_H_
#error "Direct inclusion of this file is not allowed, include leaky_singleton.h"
// For the sake of sane code completion.
#include "leaky_singleton.h"
#endif

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

template <class T>
TLeakyStorage<T>::TLeakyStorage()
{
    new (Get()) T();
}

template <class T>
T* TLeakyStorage<T>::Get()
{
    return reinterpret_cast<T*>(Buffer_);
}

////////////////////////////////////////////////////////////////////////////////

template <class T>
T* LeakySingleton()
{
    static TLeakyStorage<T> Storage;
    return Storage.Get();
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT