File tree Expand file tree Collapse file tree 2 files changed +382
-57
lines changed Expand file tree Collapse file tree 2 files changed +382
-57
lines changed Original file line number Diff line number Diff line change
1
+ #ifndef __NBL_CORE_STORAGE_TRIVIALIZER_H_INCLUDED__
2
+ #define __NBL_CORE_STORAGE_TRIVIALIZER_H_INCLUDED__
3
+
4
+ namespace nbl ::core
5
+ {
6
+
7
+ // This construct makes it so that we don't trigger T's constructors and destructors.
8
+ template <typename T>
9
+ struct StorageTrivializer ;
10
+
11
+ template <>
12
+ struct NBL_FORCE_EBO StorageTrivializer<void >
13
+ {
14
+ void * getStorage () {return nullptr ;}
15
+ const void * getStorage () const {return nullptr ;}
16
+
17
+ void construct () {}
18
+ void destruct () {}
19
+ };
20
+
21
+ template <typename T>
22
+ struct alignas (T) StorageTrivializer
23
+ {
24
+ T* getStorage () {return reinterpret_cast <T*>(storage); }
25
+ const T* getStorage () const {return reinterpret_cast <const T*>(storage);}
26
+
27
+ void construct (Args&&... args)
28
+ {
29
+ new (getStorage ()) T (std::forward<Args>(args)...);
30
+ }
31
+ void destruct ()
32
+ {
33
+ getStorage->~T ();
34
+ }
35
+
36
+ uint8_t * storage[sizeof (T)];
37
+ };
38
+
39
+ }
40
+
41
+ #endif
You can’t perform that action at this time.
0 commit comments