70 #ifndef LIB_UNINITIALISED_STORAGE_H 71 #define LIB_UNINITIALISED_STORAGE_H 87 template<
typename T,
size_t cnt>
90 using _Arr = std::array<T,cnt>;
91 alignas(T) std::byte buffer_[
sizeof(_Arr)];
97 return * std::launder (reinterpret_cast<_Arr* > (&buffer_));
103 return * std::launder (reinterpret_cast<_Arr const*> (&buffer_));
107 operator _Arr&() {
return array(); }
108 operator _Arr
const&()
const {
return array(); }
110 T & operator[] (
size_t idx) {
return array()[idx]; }
111 T
const& operator[] (
size_t idx)
const {
return array()[idx]; }
114 template<
typename...Args>
116 createAt (
size_t idx, Args&& ...args)
118 return *
new(&operator[](idx)) T{std::forward<Args>(args)...};
122 destroyAt (
size_t idx)
124 operator[](idx).~T();
140 void* buff_{
nullptr};
147 if (buff_) discard();
149 buff_ = cnt? std::aligned_alloc (std::alignment_of<T>(), cnt *
sizeof(T))
189 std::swap (u1.size_, u2.size_);
190 std::swap (u1.buff_, u2.buff_);
194 operator bool()
const 209 return * std::launder (reinterpret_cast<_Arr* > (buff_));
215 return * std::launder (reinterpret_cast<_Arr const*> (buff_));
219 T * front() {
return &array()[0]; }
220 T
const* front()
const {
return &array()[0]; }
221 T * after() {
return &array()[size_];}
222 T
const* after()
const {
return &array()[size_];}
223 T * back () {
return after() - 1; }
224 T
const* back ()
const {
return after() - 1; }
226 T & operator[] (
size_t idx) {
return array()[idx]; }
227 T
const& operator[] (
size_t idx)
const {
return array()[idx]; }
230 template<
typename...Args>
232 createAt (
size_t idx, Args&& ...args)
234 return *
new(&operator[](idx)) T{std::forward<Args>(args)...};
238 destroyAt (
size_t idx)
240 operator[](idx).~T();
Implementation namespace for support and library code.
Block of raw uninitialised storage with array like access.
Managed uninitialised Heap-allocated storage with array like access.