File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 21
21
#include < functional>
22
22
#include < numeric>
23
23
#include < sstream>
24
- #include < stdalign.h>
25
24
#include < string>
26
25
#include < type_traits>
27
26
#include < typeindex>
@@ -55,16 +54,21 @@ class LazyInitializeAtLeastOnceDestroyNever {
55
54
// Multiple threads may run this concurrently, but that is fine.
56
55
auto value = initialize (); // May release and re-acquire the GIL.
57
56
if (!initialized_) { // This runs with the GIL held,
58
- new // therefore this is reached only once.
59
- ( reinterpret_cast <T *>(value_storage_)) T (std::move (value));
57
+ new (&value_) // therefore this is reached only once.
58
+ T (std::move (value));
60
59
initialized_ = true ;
61
60
}
62
61
}
63
- return * reinterpret_cast <T *>(value_storage_) ;
62
+ return value_ ;
64
63
}
65
64
65
+ LazyInitializeAtLeastOnceDestroyNever () {}
66
+ ~LazyInitializeAtLeastOnceDestroyNever () {}
67
+
66
68
private:
67
- alignas (T) char value_storage_[sizeof (T)];
69
+ union {
70
+ T value_;
71
+ };
68
72
bool initialized_ = false ;
69
73
};
70
74
You can’t perform that action at this time.
0 commit comments