5#include <initializer_list>
40 template<
typename TYPE,
typename ALLOC = allocator<TYPE>>
58 void arrDestruct()
noexcept;
89 Iterator(
const Iterator& other);
144 array(
const std::initializer_list<TYPE>& lst);
235 Iterator*
ends()
const override;
252 template<
typename TYPE,
typename ALLOC>
253 void original::array<TYPE, ALLOC>::arrInit(
const u_integer size) {
255 this->body = this->allocate(this->size_);
256 for (u_integer i = 0; i < this->size(); ++i) {
257 this->construct(&this->body[i]);
261 template<
typename TYPE,
typename ALLOC>
262 void original::array<TYPE, ALLOC>::arrDestruct() noexcept
265 for (u_integer i = 0; i < this->size_; ++i) {
266 this->destroy(&this->body[i]);
268 this->deallocate(this->body, this->size_);
272 template<
typename TYPE,
typename ALLOC>
273 original::array<TYPE, ALLOC>::Iterator::Iterator(TYPE* ptr,
const array* container, integer pos)
274 : randomAccessIterator<TYPE, ALLOC>(ptr, container, pos) {}
276 template<
typename TYPE,
typename ALLOC>
277 original::array<TYPE, ALLOC>::Iterator::Iterator(
const Iterator& other)
283 template<
typename TYPE,
typename ALLOC>
286 if (
this == &other) {
293 template<
typename TYPE,
typename ALLOC>
295 return new Iterator(*
this);
298 template<
typename TYPE,
typename ALLOC>
300 auto other_it =
dynamic_cast<const Iterator*
>(other);
301 return this->
_ptr + 1 == other_it->_ptr;
304 template<
typename TYPE,
typename ALLOC>
306 auto other_it =
dynamic_cast<const Iterator*
>(other);
307 return other_it->_ptr + 1 == this->
_ptr;
310 template<
typename TYPE,
typename ALLOC>
312 return "array::Iterator";
315 template<
typename TYPE,
typename ALLOC>
317 :
baseArray<TYPE, ALLOC>(std::move(alloc)), size_(), body(nullptr) {
321 template<
typename TYPE,
typename ALLOC>
325 for (
const auto& e : lst) {
331 template<
typename TYPE,
typename ALLOC>
337 template<
typename TYPE,
typename ALLOC>
345 this->arrInit(other.size());
346 for (
u_integer i = 0; i < this->size_; i++) {
347 this->body[i] = other.body[i];
349 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
355 template<
typename TYPE,
typename ALLOC>
360 template<
typename TYPE,
typename ALLOC>
367 this->body = other.body;
368 this->size_ = other.size_;
369 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
370 this->
allocator = std::move(other.allocator);
376 template<
typename TYPE,
typename ALLOC>
381 template<
typename TYPE,
typename ALLOC>
387 template<
typename TYPE,
typename ALLOC>
389 return this->body[0];
392 template<
typename TYPE,
typename ALLOC>
401 template<
typename TYPE,
typename ALLOC>
410 template<
typename TYPE,
typename ALLOC>
419 template<
typename TYPE,
typename ALLOC>
422 for (
u_integer i = 0; i < this->size(); i += 1)
424 if (this->
get(i) == e)
432 template<
typename TYPE,
typename ALLOC>
434 return new Iterator(&this->body[0],
this, 0);
437 template<
typename TYPE,
typename ALLOC>
439 return new Iterator(&this->body[this->size() - 1],
this, this->size() - 1);
442 template<
typename TYPE,
typename ALLOC>
Memory allocation interface and implementations.
Provides a base class for fixed-size serial containers.
Default memory allocator using allocators utilities.
Definition allocator.h:154
Iterator for the array class that supports random access.
Definition array.h:72
std::string className() const override
Returns the class name of this iterator.
Definition array.h:311
Iterator & operator=(const Iterator &other)
Copy assignment operator for the iterator.
Definition array.h:284
bool atNext(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just after the given iterator.
Definition array.h:305
Iterator * clone() const override
Clones the iterator.
Definition array.h:294
bool atPrev(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just before the given iterator.
Definition array.h:299
A fixed-size array container with random access.
Definition array.h:41
array & operator=(array &&other) noexcept
Move assignment operator.
Definition array.h:361
std::string className() const override
Returns the class name.
Definition array.h:443
void set(integer index, const TYPE &e) override
Sets the value of an element at the specified index.
Definition array.h:411
Iterator * ends() const override
Returns an iterator to the last element of the array.
Definition array.h:438
TYPE get(integer index) const override
Retrieves an element at a specified index.
Definition array.h:393
array(array &&other) noexcept
Move constructor.
Definition array.h:356
array(const std::initializer_list< TYPE > &lst)
Constructs an array from an initializer list.
Definition array.h:322
array(u_integer size=0, ALLOC alloc=ALLOC{})
Constructs an empty array.
Definition array.h:316
TYPE & data() const
Returns a reference to the first element of the array.
Definition array.h:388
~array() override
Destroys the array and releases its memory.
Definition array.h:377
array(const array &other)
Copy constructor.
Definition array.h:332
array & operator=(const array &other)
Copy assignment operator.
Definition array.h:338
u_integer indexOf(const TYPE &e) const override
Finds the index of the specified element in the array.
Definition array.h:420
TYPE & operator[](integer index) override
Access an element at a specified index for modification.
Definition array.h:402
u_integer size() const override
Returns the size of the array.
Definition array.h:382
Iterator * begins() const override
Returns an iterator to the first element of the array.
Definition array.h:433
Base class for fixed-size serial containers.
Definition baseArray.h:43
Abstract base class for containers.
Definition container.h:28
A stream class that allows iteration, comparison, and printing.
Definition iterationStream.h:33
Base iterator interface that supports common operations for iteration.
Definition iterator.h:35
Exception for container index out-of-range errors.
Definition error.h:84
randomAccessIterator(TYPE *ptr, const container< TYPE, ALLOC > *container, integer pos)
Protected constructor for derived classes.
Definition randomAccessIterator.h:181
randomAccessIterator & operator=(const randomAccessIterator &other)
Copy assignment operator.
Definition randomAccessIterator.h:197
TYPE * _ptr
Pointer to the current element.
Definition randomAccessIterator.h:41
bool indexOutOfBound(integer index) const
Checks if the provided index is out of bounds.
Definition serial.h:133
integer parseNegIndex(integer index) const
Converts negative indices into valid positive indices.
Definition serial.h:140
Platform-independent integer type definitions.
Custom exception classes and callback validation utilities.
Provides functionality for an iteration stream.
Main namespace for the project Original.
Definition algorithms.h:21
std::uint32_t u_integer
32-bit unsigned integer type for sizes/indexes
Definition config.h:17
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:15
Base class for random-access iterators.