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);
211 using serial<TYPE, ALLOC>::operator[];
238 Iterator*
ends()
const override;
255 template<
typename TYPE,
typename ALLOC>
256 void original::array<TYPE, ALLOC>::arrInit(
const u_integer size) {
258 this->body = this->allocate(this->size_);
259 for (u_integer i = 0; i < this->size(); ++i) {
260 this->construct(&this->body[i]);
264 template<
typename TYPE,
typename ALLOC>
265 void original::array<TYPE, ALLOC>::arrDestruct() noexcept
268 for (u_integer i = 0; i < this->size_; ++i) {
269 this->destroy(&this->body[i]);
271 this->deallocate(this->body, this->size_);
272 this->body =
nullptr;
276 template<
typename TYPE,
typename ALLOC>
277 original::array<TYPE, ALLOC>::Iterator::Iterator(TYPE* ptr,
const array* container, integer pos)
278 : randomAccessIterator<TYPE, ALLOC>(ptr, container, pos) {}
280 template<
typename TYPE,
typename ALLOC>
281 original::array<TYPE, ALLOC>::Iterator::Iterator(
const Iterator& other)
287 template<
typename TYPE,
typename ALLOC>
290 if (
this == &other) {
297 template<
typename TYPE,
typename ALLOC>
299 return new Iterator(*
this);
302 template<
typename TYPE,
typename ALLOC>
304 auto other_it =
dynamic_cast<const Iterator*
>(other);
305 return this->
_ptr + 1 == other_it->_ptr;
308 template<
typename TYPE,
typename ALLOC>
310 auto other_it =
dynamic_cast<const Iterator*
>(other);
311 return other_it->_ptr + 1 == this->
_ptr;
314 template<
typename TYPE,
typename ALLOC>
316 return "array::Iterator";
319 template<
typename TYPE,
typename ALLOC>
321 :
baseArray<TYPE, ALLOC>(std::move(alloc)), size_(), body(nullptr) {
325 template<
typename TYPE,
typename ALLOC>
329 for (
const auto& e : lst) {
335 template<
typename TYPE,
typename ALLOC>
341 template<
typename TYPE,
typename ALLOC>
349 this->arrInit(other.size());
350 for (
u_integer i = 0; i < this->size_; i++) {
351 this->body[i] = other.body[i];
353 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
359 template<
typename TYPE,
typename ALLOC>
364 template<
typename TYPE,
typename ALLOC>
371 this->body = other.body;
372 this->size_ = other.size_;
373 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
374 this->
allocator = std::move(other.allocator);
380 template<
typename TYPE,
typename ALLOC>
385 template<
typename TYPE,
typename ALLOC>
391 template<
typename TYPE,
typename ALLOC>
393 return this->body[0];
396 template<
typename TYPE,
typename ALLOC>
405 template<
typename TYPE,
typename ALLOC>
414 template<
typename TYPE,
typename ALLOC>
423 template<
typename TYPE,
typename ALLOC>
426 for (
u_integer i = 0; i < this->size(); i += 1)
428 if (this->
get(i) == e)
436 template<
typename TYPE,
typename ALLOC>
438 return new Iterator(&this->body[0],
this, 0);
441 template<
typename TYPE,
typename ALLOC>
443 return new Iterator(&this->body[this->size() - 1],
this, this->size() - 1);
446 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:315
Iterator & operator=(const Iterator &other)
Copy assignment operator for the iterator.
Definition array.h:288
bool atNext(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just after the given iterator.
Definition array.h:309
Iterator * clone() const override
Clones the iterator.
Definition array.h:298
bool atPrev(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just before the given iterator.
Definition array.h:303
A fixed-size array container with random access.
Definition array.h:41
array & operator=(array &&other) noexcept
Move assignment operator.
Definition array.h:365
std::string className() const override
Returns the class name.
Definition array.h:447
void set(integer index, const TYPE &e) override
Sets the value of an element at the specified index.
Definition array.h:415
Iterator * ends() const override
Returns an iterator to the last element of the array.
Definition array.h:442
TYPE get(integer index) const override
Retrieves an element at a specified index.
Definition array.h:397
array(array &&other) noexcept
Move constructor.
Definition array.h:360
array(const std::initializer_list< TYPE > &lst)
Constructs an array from an initializer list.
Definition array.h:326
array(u_integer size=0, ALLOC alloc=ALLOC{})
Constructs an empty array.
Definition array.h:320
TYPE & data() const
Returns a reference to the first element of the array.
Definition array.h:392
~array() override
Destroys the array and releases its memory.
Definition array.h:381
array(const array &other)
Copy constructor.
Definition array.h:336
array & operator=(const array &other)
Copy assignment operator.
Definition array.h:342
u_integer indexOf(const TYPE &e) const override
Finds the index of the specified element in the array.
Definition array.h:424
TYPE & operator[](integer index) override
Access an element at a specified index for modification.
Definition array.h:406
u_integer size() const override
Returns the size of the array.
Definition array.h:386
Iterator * begins() const override
Returns an iterator to the first element of the array.
Definition array.h:437
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:37
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
Abstract base class for sequential containers with index-based access.
Definition serial.h:34
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 and floating-point 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 and indexes
Definition config.h:43
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:35
Base class for random-access iterators.