31#ifndef FENNEC_CONTAINERS_DYNARRAY_H
32#define FENNEC_CONTAINERS_DYNARRAY_H
63template<
class TypeT,
class Alloc = allocator<TypeT>>
111 for(; n > 0; --n, ++addr) {
112 fennec::construct(addr);
125 for(; n > 0; --n, ++addr) {
126 fennec::construct(addr);
139 for(; n > 0; --n, ++addr) {
140 fennec::construct(addr);
153 for(; n > 0; --n, ++addr) {
154 fennec::construct(addr, val);
160 constexpr dynarray(
size_t n, TypeT&& val) =
delete;
167 template<
typename...ArgsT>
168 constexpr explicit dynarray(
size_t n, ArgsT&&...args)
172 fennec::construct(&_alloc[n], fennec::forward<ArgsT>(args)...);
184 for (
size_t i = 0; i < N; ++i) {
197 for (
size_t i = 0; i < N; ++i) {
207 template<
typename OTypeT,
class OAlloc>
209 : _alloc(conv.
size())
210 , _size(conv.
size()) {
212 for (
const auto& it : conv) {
213 fennec::construct(&_alloc[i++], it);
222 : _alloc(l.
size(), alloc)
236 for (
size_t i = 0; i < _size; ++i) {
237 fennec::construct(&_alloc[i], arr[i]);
245 : _alloc(fennec::move(arr._alloc))
254 if (addr ==
nullptr)
return;
255 for(
int n = _size; n > 0; --n, ++addr) {
256 fennec::destruct(addr);
274 for (
size_t i = 0; i < _size; ++i) {
301 for (
size_t i = 0; i < _size; ++i) {
316 for (
size_t i = 0; i < _size; ++i) {
331 constexpr size_t size()
const {
360 assertd(i < _size,
"Array Out of Bounds");
361 return _alloc.
data()[i];
369 assertd(i < _size,
"Array Out of Bounds");
370 return _alloc.
data()[i];
381 constexpr const TypeT&
front()
const {
393 constexpr const TypeT&
back()
const {
409 constexpr void insert(
size_t i, TypeT&& val) {
417 if((i =
min(i, _size)) < _size) {
419 (
void*)(_alloc.
data() + i + 1)
420 , (
void*)(_alloc.
data() + i)
421 , (_size - i) *
sizeof(TypeT));
425 fennec::construct(_alloc.
data() + i, fennec::forward<TypeT>(val));
433 constexpr void insert(
size_t i,
const TypeT& val) {
441 if((i =
min(i, _size)) < _size) {
443 (
void*)(_alloc.
data() + i),
444 (
void*)(_alloc.
data() + i + 1),
445 (_size - i) *
sizeof(TypeT)
450 fennec::construct(_alloc.
data() + i, val);
459 template<
typename...ArgsT>
460 constexpr void emplace(
size_t i, ArgsT&&...args) {
468 if((i =
min(i, _size)) < _size) {
470 (
void*)(_alloc.
data() + i)
471 , (
void*)(_alloc.
data() + i + 1)
472 , (_size - i) *
sizeof(TypeT));
476 fennec::construct(_alloc.
data() + i, fennec::forward<ArgsT>(args)...);
498 template<
typename...ArgsT>
506 fennec::destruct(&_alloc[--_size]);
524 constexpr void resize(
size_t n,
const TypeT& val) {
536 fennec::destruct(&_alloc[--_size]);
562 constexpr const TypeT*
begin()
const {
return _alloc; }
567 constexpr const TypeT*
end()
const {
return begin() + _size; }
572 constexpr void _grow() {
576 allocation<value_t, alloc_t> _alloc;
This header contains structures and classes related to allocating blocks of memory.
constexpr genType min(genType x, genType y)
Returns if otherwise it returns .
Definition common.h:688
This header contains functions related to analyzing, modifying or copying buffers interpreted as byte...
constexpr value_t * data()
Getter for the real pointer to the allocated block of memory.
Definition allocator.h:624
constexpr size_t capacity() const
Getter for the number of elements n of type T that the allocation can hold.
Definition allocator.h:617
constexpr void deallocate() noexcept
Release the block of memory.
Definition allocator.h:505
constexpr void creallocate(size_t n, align_t align=zero< align_t >()) noexcept
Reallocate the block with a new size. Contents are copied to the new allocation.
Definition allocator.h:541
Wrapper for dynamically sized and allocated arrays.
Definition dynarray.h:64
constexpr void emplace_back(ArgsT...args)
Emplace Back.
Definition dynarray.h:499
constexpr dynarray & operator=(const TypeT(&arr)[N])
Array Copy Assignment Operator.
Definition dynarray.h:298
constexpr ~dynarray()
Default Destructor, destructs all elements and frees the underlying allocation.
Definition dynarray.h:252
constexpr TypeT * end()
"Iterator" End Function
Definition dynarray.h:557
constexpr dynarray(size_t n, alloc_t &&alloc)
Sized Allocation Alloc Move Constructor, initializes a dynarray with allocator alloc and n elements u...
Definition dynarray.h:135
constexpr const TypeT & back() const
Definition dynarray.h:393
constexpr TypeT & operator[](size_t i)
Array Access Operator.
Definition dynarray.h:359
constexpr dynarray & operator=(TypeT(&&arr)[N])
Array Copy Assignment Operator.
Definition dynarray.h:313
constexpr bool empty() const
Definition dynarray.h:343
constexpr void insert(size_t i, TypeT &&val)
Move Insertion.
Definition dynarray.h:409
constexpr dynarray(size_t n, const alloc_t &alloc)
Sized Allocation Alloc Constructor, initializes a dynarray with allocator alloc and n elements using ...
Definition dynarray.h:121
constexpr dynarray()
Default Constructor, initializes an empty allocation.
Definition dynarray.h:80
constexpr TypeT & front()
Definition dynarray.h:375
constexpr void clear()
Clears the contents of the dynarray, destructing all elements and releasing the allocation.
Definition dynarray.h:534
constexpr const TypeT * end() const
Const "Iterator" End Function.
Definition dynarray.h:567
constexpr dynarray(const dynarray< OTypeT, OAlloc > &conv)
Conversion Constructor, copies elements of conv as this value_t
Definition dynarray.h:208
constexpr dynarray(TypeT(&&arr)[N])
Array Move Constructor.
Definition dynarray.h:194
constexpr dynarray(size_t n)
Sized Allocation, initializes a dynarray with n elements using the default constructor.
Definition dynarray.h:106
constexpr void pop_back()
Erase last element.
Definition dynarray.h:505
constexpr void push_back(TypeT &&val)
Push Back Move.
Definition dynarray.h:490
constexpr dynarray & operator=(dynarray &&arr) noexcept
Move Assignment Operator.
Definition dynarray.h:284
constexpr dynarray(dynarray &&arr) noexcept
Move Constructor, takes ownership of the allocation.
Definition dynarray.h:244
constexpr dynarray(size_t n, ArgsT &&...args)
Emplace Constructor.
Definition dynarray.h:168
constexpr const TypeT & operator[](size_t i) const
Array Access Operator (const)
Definition dynarray.h:368
constexpr const TypeT & front() const
Definition dynarray.h:381
constexpr void push_back(const TypeT &val)
Push Back Copy.
Definition dynarray.h:483
constexpr size_t capacity() const
Definition dynarray.h:337
constexpr const TypeT * begin() const
Const "Iterator" Begin Function.
Definition dynarray.h:562
constexpr TypeT & back()
Definition dynarray.h:387
constexpr dynarray(const dynarray &arr)
Copy Constructor, uses the copy constructor to copy each element.
Definition dynarray.h:233
constexpr void insert(size_t i, const TypeT &val)
Copy Insertion.
Definition dynarray.h:433
constexpr void resize(size_t n, const TypeT &val)
Resize the dynarray, invoking the copy constructor for all new elements.
Definition dynarray.h:524
constexpr void emplace(size_t i, ArgsT &&...args)
Emplace Insertion.
Definition dynarray.h:460
constexpr dynarray(alloc_t &&alloc) noexcept
Alloc Move Constructor, initialize empty allocation with allocator instance.
Definition dynarray.h:98
Alloc alloc_t
Alias for the allocator type.
Definition dynarray.h:70
constexpr dynarray & operator=(const dynarray &arr)
Copy Assignment Operator.
Definition dynarray.h:271
constexpr dynarray(size_t n, const TypeT &val)
Sized Allocation Copy Constructor, Create an allocation of size n elements, with each element constru...
Definition dynarray.h:149
constexpr size_t size() const
Definition dynarray.h:331
TypeT value_t
Alias for the value type.
Definition dynarray.h:69
constexpr void resize(size_t n)
Resize the dynarray, invoking the default constructor for all new elements.
Definition dynarray.h:512
constexpr dynarray(initializer_list< value_t > l, const alloc_t &alloc=alloc_t())
Initializer List Constructor.
Definition dynarray.h:221
constexpr dynarray(const TypeT(&arr)[N])
Array Copy Constructor.
Definition dynarray.h:181
constexpr dynarray(const alloc_t &alloc)
Alloc Constructor, initialize empty allocation with allocator instance.
Definition dynarray.h:89
constexpr TypeT * begin()
"Iterator" Begin Function
Definition dynarray.h:552
constexpr const remove_reference_t< T > & copy(T &&x) noexcept
produces an r-value type to indicate x may be "copied"
Definition utility.h:104
constexpr remove_reference_t< T > && move(T &&x) noexcept
produces an x-value type to indicate x may be "moved"
Definition utility.h:92