94namespace ArrayOptions {
110template <
typename T,
size_t Capacity>
120 _buff =
new T[Capacity + 1];
128 void clone(
const b8array& obj) {
134 for (
size_t nn = 0; nn < _size; ++nn) {
135 _buff[nn] = obj._buff[nn];
147 if (option == ArrayOptions::Fill) {
149 for (
size_t ii = 0; ii < Capacity; ++ii) {
163 for (
const auto& val : il) {
164 _ASSERT(index < Capacity,
"Capacity exceeded by initializer list");
165 if (index < Capacity) {
166 _buff[index++] = val;
236 return _buff + _size;
245 return _buff + _size;
263 return _buff + _size;
273 _ASSERT(it_ >= _buff && it_ < _buff + _size,
"Invalid iterator");
274 if (it_ < _buff || it_ >= _buff + _size) {
275 return _buff + _size;
277 for (T* p = it_; p < _buff + _size - 1; ++p) {
306 _ASSERT(_size < Capacity,
"over flow");
317 _ASSERT(n_ >= 0,
"array exception");
318 _ASSERT(n_ <
static_cast<int>(
size()),
"array exception");
328 const T&
at(
int n_)
const {
329 _ASSERT(n_ >= 0,
"array exception");
330 _ASSERT(n_ <
static_cast<int>(
size()),
"array exception");
340 _ASSERT(n_ >= 0,
"array exception");
341 _ASSERT(n_ <
static_cast<int>(
size()),
"array exception");
352 _ASSERT(n_ >= 0,
"array exception");
353 _ASSERT(n_ <
static_cast<int>(
size()),
"array exception");
InitializationOption
Enum for specifying array initialization options.
Definition array.h:98
@ NoFill
Do not fill the array.
Definition array.h:100
@ Fill
Fill the array with default-constructed elements.
Definition array.h:99
A fixed-size array with custom behavior for element initialization.
Definition array.h:111
void clear()
Clear the contents of the array.
Definition array.h:287
b8array(ArrayOptions::InitializationOption option=ArrayOptions::NoFill)
Construct a new b8array.
Definition array.h:145
T * begin()
Get an iterator pointing to the first element.
Definition array.h:217
T & at(int n_)
Access element at a specific position.
Definition array.h:316
b8array(const b8array &obj)
Copy constructor for b8array.
Definition array.h:177
const T * end() const
Get a const iterator pointing to one past the last element.
Definition array.h:262
const T * begin() const
Get a const iterator pointing to the first element.
Definition array.h:253
T * end()
Get an iterator pointing to one past the last element.
Definition array.h:244
b8array & operator=(const b8array &obj)
Copy assignment operator.
Definition array.h:187
bool empty() const
Check if the array is empty.
Definition array.h:208
T * erase(T *it_)
Erase an element from the array.
Definition array.h:272
b8array(std::initializer_list< T > il)
Construct a new b8array with an initializer list.
Definition array.h:160
const T & at(int n_) const
Access element at a specific position (const version).
Definition array.h:328
const T * cbegin() const
Get a const iterator pointing to the first element.
Definition array.h:226
~b8array()
Destructor to release allocated memory.
Definition array.h:197
T & operator[](int n_)
Overload array subscript operator for non-const objects.
Definition array.h:339
size_t size() const
Get the number of elements in the array.
Definition array.h:296
const T * cend() const
Get a const iterator pointing to one past the last element.
Definition array.h:235
const T & operator[](int n_) const
Overload array subscript operator for const objects.
Definition array.h:351
void push_back(const T &x_)
Add an element to the end of the array.
Definition array.h:305
Debug tracing macros for logging and monitoring program execution.