5#include <initializer_list>
40 template<
typename TYPE,
typename ALLOC = allocator<TYPE>>
58 void arrDestroy()
noexcept;
269 Iterator*
ends()
const override;
293 template<
typename TYPE,
typename ALLOC>
297 template<
typename TYPE,
typename ALLOC>
300 this->body = this->allocate(this->size_);
301 for (
u_integer i = 0; i < this->size(); ++i) {
302 this->construct(&this->body[i]);
306 template<
typename TYPE,
typename ALLOC>
310 for (
u_integer i = 0; i < this->size_; ++i) {
311 this->destroy(&this->body[i]);
313 this->deallocate(this->body, this->size_);
314 this->body =
nullptr;
318 template <
typename TYPE,
typename ALLOC>
321 if constexpr (std::is_copy_constructible_v<TYPE>) {
322 return this->body[pos];
323 }
else if constexpr (std::is_move_constructible_v<TYPE>) {
324 return std::move(this->body[pos]);
326 staticError<unSupportedMethodError, !std::is_copy_constructible_v<TYPE> && !std::is_move_constructible_v<TYPE>>::asserts();
331 template <
typename TYPE,
typename ALLOC>
334 if constexpr (std::is_copy_assignable_v<TYPE>) {
336 }
else if constexpr (std::is_move_assignable_v<TYPE>) {
337 this->body[pos] = std::move(
const_cast<TYPE&
>(e));
339 staticError<unSupportedMethodError, !std::is_copy_constructible_v<TYPE> && !std::is_move_constructible_v<TYPE>>::asserts();
343 template<
typename TYPE,
typename ALLOC>
345 : randomAccessIterator<TYPE, ALLOC>(ptr, container, pos) {}
347 template<
typename TYPE,
typename ALLOC>
354 template<
typename TYPE,
typename ALLOC>
357 if (
this == &
other) {
364 template<
typename TYPE,
typename ALLOC>
369 template<
typename TYPE,
typename ALLOC>
372 return this->_ptr + 1 ==
other_it->_ptr;
375 template<
typename TYPE,
typename ALLOC>
378 return other_it->_ptr + 1 == this->_ptr;
381 template<
typename TYPE,
typename ALLOC>
383 return "array::Iterator";
386 template<
typename TYPE,
typename ALLOC>
392 template<
typename TYPE,
typename ALLOC>
396 for (
const auto&
e :
lst) {
402 template<
typename TYPE,
typename ALLOC>
408 template<
typename TYPE,
typename ALLOC>
416 this->arrInit(
other.size());
418 this->setElem(
i,
other.getElem(
i));
420 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
426 template<
typename TYPE,
typename ALLOC>
428 this->operator=(std::move(
other));
431 template<
typename TYPE,
typename ALLOC>
438 this->body =
other.body;
439 this->size_ =
other.size_;
440 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
447 template <
typename TYPE,
typename ALLOC>
454 if constexpr (ALLOC::propagate_on_container_swap::value) {
459 template<
typename TYPE,
typename ALLOC>
464 template<
typename TYPE,
typename ALLOC>
470 template<
typename TYPE,
typename ALLOC>
472 return this->body[0];
475 template<
typename TYPE,
typename ALLOC>
478 if (this->indexOutOfBound(index)){
480 " out of bound max index " +
std::to_string(this->size() - 1) +
".");
482 return this->getElem(this->parseNegIndex(index));
485 template<
typename TYPE,
typename ALLOC>
488 if (this->indexOutOfBound(index)){
490 " out of bound max index " +
std::to_string(this->size() - 1) +
".");
492 return this->body[this->parseNegIndex(index)];
495 template<
typename TYPE,
typename ALLOC>
498 if (this->indexOutOfBound(index)){
500 " out of bound max index " +
std::to_string(this->size() - 1) +
".");
502 this->setElem(this->parseNegIndex(index),
e);
505 template<
typename TYPE,
typename ALLOC>
512 if (this->get(
i) ==
e)
523 template<
typename TYPE,
typename ALLOC>
525 return new Iterator(&this->body[0],
this, 0);
528 template<
typename TYPE,
typename ALLOC>
530 return new Iterator(&this->body[this->size() - 1],
this, this->size() - 1);
533 template<
typename TYPE,
typename ALLOC>
539 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:153
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:382
Iterator & operator=(const Iterator &other)
Copy assignment operator for the iterator.
Definition array.h:355
bool atNext(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just after the given iterator.
Definition array.h:376
Iterator * clone() const override
Clones the iterator.
Definition array.h:365
bool atPrev(const iterator< TYPE > *other) const override
Checks if this iterator is positioned just before the given iterator.
Definition array.h:370
A fixed-size array container with random access.
Definition array.h:41
void swap(array &other) noexcept
Swaps the contents of two arrays.
Definition array.h:448
array & operator=(array &&other) noexcept
Move assignment operator.
Definition array.h:432
std::string className() const override
Returns the class name.
Definition array.h:534
void set(integer index, const TYPE &e) override
Sets the value of an element at the specified index.
Definition array.h:496
Iterator * ends() const override
Returns an iterator to the last element of the array.
Definition array.h:529
TYPE get(integer index) const override
Retrieves an element at a specified index.
Definition array.h:476
array(array &&other) noexcept
Move constructor.
Definition array.h:427
array(const std::initializer_list< TYPE > &lst)
Constructs an array from an initializer list.
Definition array.h:393
array(u_integer size=0, ALLOC alloc=ALLOC{})
Constructs an empty array.
Definition array.h:387
TYPE & data() const
Returns a reference to the first element of the array.
Definition array.h:471
~array() override
Destroys the array and releases its memory.
Definition array.h:460
array(const array &other)
Copy constructor.
Definition array.h:403
array & operator=(const array &other)
Copy assignment operator.
Definition array.h:409
u_integer indexOf(const TYPE &e) const override
Finds the index of the specified element in the array.
Definition array.h:506
TYPE & operator[](integer index) override
Access an element at a specified index for modification.
Definition array.h:486
u_integer size() const override
Returns the size of the array.
Definition array.h:465
Iterator * begins() const override
Returns an iterator to the first element of the array.
Definition array.h:524
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:703
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, hashing and printing.
Definition iterationStream.h:60
Exception for container index out-of-range errors.
Definition error.h:192
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Abstract base class for random-access iterators.
Definition randomAccessIterator.h:39
randomAccessIterator & operator=(const randomAccessIterator &other)
Copy assignment operator.
Definition randomAccessIterator.h:197
Abstract base class for sequential containers with index-based access.
Definition serial.h:34
Exception for unimplemented method calls.
Definition error.h:271
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 with comparison, hashing and printing.
Main namespace for the project Original.
Definition algorithms.h:21
Standard namespace extensions for original::alternative.
Definition allocator.h:351
std::string to_string(const T &t)
std::to_string overload for printable-derived types
Definition printable.h:415
void swap(original::objPoolAllocator< TYPE > &lhs, original::objPoolAllocator< TYPE > &rhs) noexcept
Specialization of std::swap for objPoolAllocator.
Definition allocator.h:635
Base class for random-access iterators.