blob: 7a7b28a5826b1981662e6d73221b13bc493f3b49 (
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
|
#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
#include <utility>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
template <class T>
template <class... TArgs>
TLeakyStorage<T>::TLeakyStorage(TArgs&&... args)
{
new (Get()) T(std::forward<TArgs>(args)...);
}
template <class T>
T* TLeakyStorage<T>::Get()
{
return reinterpret_cast<T*>(Buffer_);
}
////////////////////////////////////////////////////////////////////////////////
template <class T, class... TArgs>
T* LeakySingleton(TArgs&&... args)
{
static TLeakyStorage<T> Storage(std::forward<TArgs>(args)...);
return Storage.Get();
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|