61 #ifndef LIB_UNINITIALISED_STORAGE_H 62 #define LIB_UNINITIALISED_STORAGE_H 78 template<
typename T,
size_t cnt>
81 using _Arr = std::array<T,cnt>;
82 alignas(T) std::byte buffer_[
sizeof(_Arr)];
88 return * std::launder (reinterpret_cast<_Arr* > (&buffer_));
94 return * std::launder (reinterpret_cast<_Arr const*> (&buffer_));
98 operator _Arr&() {
return array(); }
99 operator _Arr
const&()
const {
return array(); }
101 T & operator[] (
size_t idx) {
return array()[idx]; }
102 T
const& operator[] (
size_t idx)
const {
return array()[idx]; }
105 template<
typename...Args>
107 createAt (
size_t idx, Args&& ...args)
109 return *
new(&operator[](idx)) T{std::forward<Args>(args)...};
113 destroyAt (
size_t idx)
115 operator[](idx).~T();
118 static constexpr
size_t size() {
return cnt; }
133 void* buff_{
nullptr};
140 if (buff_) discard();
142 buff_ = cnt? std::aligned_alloc (std::alignment_of<T>(), cnt *
sizeof(T))
183 swap (u1.size_, u2.size_);
184 swap (u1.buff_, u2.buff_);
188 operator bool()
const 203 return * std::launder (reinterpret_cast<_Arr* > (buff_));
209 return * std::launder (reinterpret_cast<_Arr const*> (buff_));
213 T * front() {
return &array()[0]; }
214 T
const* front()
const {
return &array()[0]; }
215 T * after() {
return &array()[size_];}
216 T
const* after()
const {
return &array()[size_];}
217 T * back () {
return after() - 1; }
218 T
const* back ()
const {
return after() - 1; }
220 T & operator[] (
size_t idx) {
return array()[idx]; }
221 T
const& operator[] (
size_t idx)
const {
return array()[idx]; }
224 template<
typename...Args>
226 createAt (
size_t idx, Args&& ...args)
228 return *
new(&operator[](idx)) T{std::forward<Args>(args)...};
232 destroyAt (
size_t idx)
234 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.