5#include <initializer_list>
40 template<
typename TYPE,
typename ALLOC = allocator<TYPE>>
58 void arrDestroy()
noexcept;
67 TYPE getElem(
integer pos)
const;
76 void setElem(
integer pos,
const TYPE &e);
106 Iterator(
const Iterator& other);
161 array(
const std::initializer_list<TYPE>& lst);
234 using serial<TYPE, ALLOC>::operator[];
262 Iterator*
ends()
const override;
279 template<
typename TYPE,
typename ALLOC>
282 this->body = this->allocate(this->size_);
283 for (u_integer i = 0; i < this->size(); ++i) {
284 this->construct(&this->body[i]);
288 template<
typename TYPE,
typename ALLOC>
292 for (u_integer i = 0; i < this->size_; ++i) {
293 this->destroy(&this->body[i]);
295 this->deallocate(this->body, this->size_);
296 this->body =
nullptr;
300 template <
typename TYPE,
typename ALLOC>
303 if constexpr (std::is_copy_constructible_v<TYPE>) {
304 return this->body[pos];
305 }
else if constexpr (std::is_move_constructible_v<TYPE>) {
306 return std::move(this->body[pos]);
308 staticError<unSupportedMethodError, !std::is_copy_constructible_v<TYPE> && !std::is_move_constructible_v<TYPE>>::asserts();
313 template <
typename TYPE,
typename ALLOC>
316 if constexpr (std::is_copy_assignable_v<TYPE>) {
318 }
else if constexpr (std::is_move_assignable_v<TYPE>) {
319 this->body[pos] = std::move(
const_cast<TYPE&
>(e));
321 staticError<unSupportedMethodError, !std::is_copy_constructible_v<TYPE> && !std::is_move_constructible_v<TYPE>>::asserts();
325 template<
typename TYPE,
typename ALLOC>
327 : randomAccessIterator<TYPE, ALLOC>(ptr, container, pos) {}
329 template<
typename TYPE,
typename ALLOC>
336 template<
typename TYPE,
typename ALLOC>
339 if (
this == &other) {
346 template<
typename TYPE,
typename ALLOC>
351 template<
typename TYPE,
typename ALLOC>
353 auto other_it =
dynamic_cast<const Iterator*
>(other);
354 return this->_ptr + 1 == other_it->
_ptr;
357 template<
typename TYPE,
typename ALLOC>
359 auto other_it =
dynamic_cast<const Iterator*
>(other);
360 return other_it->
_ptr + 1 == this->_ptr;
363 template<
typename TYPE,
typename ALLOC>
365 return "array::Iterator";
368 template<
typename TYPE,
typename ALLOC>
370 :
baseArray<TYPE, ALLOC>(std::move(alloc)), size_(), body(nullptr) {
374 template<
typename TYPE,
typename ALLOC>
376 :
array(lst.size()) {
378 for (
const auto& e : lst) {
384 template<
typename TYPE,
typename ALLOC>
386 :
array(other.size()) {
390 template<
typename TYPE,
typename ALLOC>
398 this->arrInit(other.size());
399 for (
u_integer i = 0; i < this->size_; i++) {
400 this->setElem(i, other.getElem(i));
402 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
408 template<
typename TYPE,
typename ALLOC>
410 this->operator=(std::move(other));
413 template<
typename TYPE,
typename ALLOC>
420 this->body = other.body;
421 this->size_ = other.size_;
422 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
423 this->
allocator = std::move(other.allocator);
429 template<
typename TYPE,
typename ALLOC>
434 template<
typename TYPE,
typename ALLOC>
440 template<
typename TYPE,
typename ALLOC>
442 return this->body[0];
445 template<
typename TYPE,
typename ALLOC>
448 if (this->indexOutOfBound(index)){
449 throw outOfBoundError(
"Index " + std::to_string(this->parseNegIndex(index)) +
450 " out of bound max index " + std::to_string(this->size() - 1) +
".");
452 return this->getElem(this->parseNegIndex(index));
455 template<
typename TYPE,
typename ALLOC>
458 if (this->indexOutOfBound(index)){
459 throw outOfBoundError(
"Index " + std::to_string(this->parseNegIndex(index)) +
460 " out of bound max index " + std::to_string(this->size() - 1) +
".");
462 return this->body[this->parseNegIndex(index)];
465 template<
typename TYPE,
typename ALLOC>
468 if (this->indexOutOfBound(index)){
469 throw outOfBoundError(
"Index " + std::to_string(this->parseNegIndex(index)) +
470 " out of bound max index " + std::to_string(this->size() - 1) +
".");
472 this->setElem(this->parseNegIndex(index), e);
475 template<
typename TYPE,
typename ALLOC>
480 for (
u_integer i = 0; i < this->size(); i += 1)
482 if (this->get(i) == e)
493 template<
typename TYPE,
typename ALLOC>
495 return new Iterator(&this->body[0],
this, 0);
498 template<
typename TYPE,
typename ALLOC>
500 return new Iterator(&this->body[this->size() - 1],
this, this->size() - 1);
503 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:89
std::string className() const override
Returns the class name of this iterator.
Definition array.h:364
Iterator & operator=(const Iterator &other)
Copy assignment operator for the iterator.
Definition array.h:337
bool atNext(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just after the given iterator.
Definition array.h:358
Iterator * clone() const override
Clones the iterator.
Definition array.h:347
bool atPrev(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just before the given iterator.
Definition array.h:352
A fixed-size array container with random access.
Definition array.h:41
array & operator=(array &&other) noexcept
Move assignment operator.
Definition array.h:414
std::string className() const override
Returns the class name.
Definition array.h:504
void set(integer index, const TYPE &e) override
Sets the value of an element at the specified index.
Definition array.h:466
Iterator * ends() const override
Returns an iterator to the last element of the array.
Definition array.h:499
TYPE get(integer index) const override
Retrieves an element at a specified index.
Definition array.h:446
array(array &&other) noexcept
Move constructor.
Definition array.h:409
array(const std::initializer_list< TYPE > &lst)
Constructs an array from an initializer list.
Definition array.h:375
array(u_integer size=0, ALLOC alloc=ALLOC{})
Constructs an empty array.
Definition array.h:369
TYPE & data() const
Returns a reference to the first element of the array.
Definition array.h:441
~array() override
Destroys the array and releases its memory.
Definition array.h:430
array(const array &other)
Copy constructor.
Definition array.h:385
array & operator=(const array &other)
Copy assignment operator.
Definition array.h:391
u_integer indexOf(const TYPE &e) const override
Finds the index of the specified element in the array.
Definition array.h:476
TYPE & operator[](integer index) override
Access an element at a specified index for modification.
Definition array.h:456
u_integer size() const override
Returns the size of the array.
Definition array.h:435
Iterator * begins() const override
Returns an iterator to the first element of the array.
Definition array.h:494
Base class for fixed-size serial containers.
Definition baseArray.h:43
Abstract base class for containers.
Definition container.h:26
A stream class that allows iteration, comparison, and printing.
Definition iterationStream.h:32
Base iterator interface that supports common operations for iteration.
Definition iterator.h:37
Exception for container index out-of-range errors.
Definition error.h:129
Abstract base class for random-access iterators.
Definition randomAccessIterator.h:39
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
Exception for unimplemented method calls.
Definition error.h:192
Platform-independent type definitions and compiler/platform detection.
Custom exception classes and callback validation utilities.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:254
Provides functionality for an iteration stream.
Main namespace for the project Original.
Definition algorithms.h:21
Base class for random-access iterators.