ORIGINAL
Loading...
Searching...
No Matches
original::array< TYPE, ALLOC > Class Template Referencefinal

A fixed-size array container with random access. More...

#include <array.h>

Inheritance diagram for original::array< TYPE, ALLOC >:
Inheritance graph
Collaboration diagram for original::array< TYPE, ALLOC >:
Collaboration graph

Classes

class  Iterator
 Iterator for the array class that supports random access. More...
 

Public Member Functions

 array (u_integer size=0, ALLOC alloc=ALLOC{})
 Constructs an empty array.
 
 array (const std::initializer_list< TYPE > &lst)
 Constructs an array from an initializer list.
 
 array (const array &other)
 Copy constructor.
 
arrayoperator= (const array &other)
 Copy assignment operator.
 
 array (array &&other) noexcept
 Move constructor.
 
arrayoperator= (array &&other) noexcept
 Move assignment operator.
 
u_integer size () const override
 Returns the size of the array.
 
TYPE & data () const
 Returns a reference to the first element of the array.
 
TYPE get (integer index) const override
 Retrieves an element at a specified index.
 
TYPE & operator[] (integer index) override
 Access an element at a specified index for modification.
 
void set (integer index, const TYPE &e) override
 Sets the value of an element at the specified index.
 
u_integer indexOf (const TYPE &e) const override
 Finds the index of the specified element in the array.
 
Iteratorbegins () const override
 Returns an iterator to the first element of the array.
 
Iteratorends () const override
 Returns an iterator to the last element of the array.
 
std::string className () const override
 Returns the class name.
 
 ~array () override
 Destroys the array and releases its memory.
 
- Public Member Functions inherited from original::iterationStream< TYPE, DERIVED >
integer compareTo (const iterationStream &other) const override
 Compares the current iteration stream with another iteration stream.
 
std::string className () const override
 Returns the class name.
 
std::string toString (bool enter) const override
 Converts the iteration stream to a string representation.
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const char * toCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE>
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE>
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE>
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE>
auto formatString (TYPE *const &ptr) -> std::string
 
- Public Member Functions inherited from original::iterable< TYPE >
iterAdaptor begin ()
 Returns an iterator pointing to the beginning of the iterable container.
 
iterAdaptor end ()
 Returns an iterator pointing to the end of the iterable container.
 
iterAdaptor begin () const
 Returns a constant iterator pointing to the beginning of the iterable container.
 
iterAdaptor end () const
 Returns a constant iterator pointing to the end of the iterable container.
 
iterAdaptor first ()
 Returns an iterator pointing to the first element.
 
iterAdaptor last ()
 Returns an iterator pointing to the last element.
 
iterAdaptor first () const
 Returns a constant iterator pointing to the first element.
 
iterAdaptor last () const
 Returns a constant iterator pointing to the last element.
 
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void forEach (Callback operation=Callback{})
 Applies a given operation to each element in the iterable container.
 
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void forEach (const Callback &operation=Callback{}) const
 Applies a given operation to each element in the iterable container (const version).
 
template<typename Callback>
requires original::Operation<Callback, TYPE>
auto forEach (Callback operation) -> void
 
template<typename Callback>
requires original::Operation<Callback, TYPE>
auto forEach (const Callback &operation) const -> void
 
- Public Member Functions inherited from original::comparable< iterationStream< TYPE, DERIVED > >
virtual integer compareTo (const DERIVED &other) const=0
 Compares the current object with another of the same type.
 
bool operator== (const DERIVED &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const DERIVED &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const DERIVED &other) const
 Checks if the current object is less than another.
 
bool operator> (const DERIVED &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const DERIVED &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const DERIVED &other) const
 Checks if the current object is greater than or equal to another.
 
virtual ~comparable ()=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::serial< TYPE, ALLOC >
virtual TYPE getBegin () const
 Retrieves the first element in the container.
 
virtual TYPE getEnd () const
 Retrieves the last element in the container.
 
virtual TYPE operator[] (integer index) const
 Retrieves the element at the specified index (const version).
 
bool contains (const TYPE &e) const override
 Checks if the container contains the specified element.
 
- Public Member Functions inherited from original::container< TYPE, ALLOC >
bool empty () const
 Checks if the container is empty.
 
virtual ~container ()=default
 Destructor for the container class.
 

Additional Inherited Members

- Static Public Member Functions inherited from original::printable
template<typename TYPE>
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion.
 
template<typename TYPE>
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting.
 
template<typename TYPE>
static const char * formatCString (const TYPE &t)
 C-string cache for temporary usage.
 
template<typename TYPE>
static std::string formatEnum (const TYPE &t)
 Enum formatting utility.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 
- Protected Member Functions inherited from original::iterationStream< TYPE, DERIVED >
std::string elementsString () const
 Returns a string representation of the elements in the stream.
 
- Protected Member Functions inherited from original::serial< TYPE, ALLOC >
bool indexOutOfBound (integer index) const
 Checks if the provided index is out of bounds.
 
integer parseNegIndex (integer index) const
 Converts negative indices into valid positive indices.
 
- Protected Member Functions inherited from original::container< TYPE, ALLOC >
 container (ALLOC alloc=ALLOC{})
 Constructs a container with specified allocator.
 
TYPE * allocate (u_integer size)
 Allocates raw memory for elements.
 
void deallocate (TYPE *ptr, u_integer size)
 Deallocates memory previously allocated by allocate()
 
template<typename O_TYPE, typename... Args>
void construct (O_TYPE *o_ptr, Args &&... args)
 Constructs an element in-place.
 
template<typename O_TYPE>
void destroy (O_TYPE *o_ptr)
 Destroys an element.
 
- Protected Attributes inherited from original::container< TYPE, ALLOC >
ALLOC allocator
 The allocator instance used for memory management.
 

Detailed Description

template<typename TYPE, typename ALLOC = allocator<TYPE>>
class original::array< TYPE, ALLOC >

A fixed-size array container with random access.

Template Parameters
TYPEType of the elements contained in the array
ALLOCAllocator type to use for memory management (default: allocator<TYPE>)

The array class encapsulates a fixed-size array and provides operations such as indexing, element assignment, and iteration. It supports random access via iterators, which can be used to traverse the container from beginning to end, and vice versa.

This class offers both copy and move semantics, along with an iterator class that supports random access operations. Memory management is handled through the specified allocator type.

Constructor & Destructor Documentation

◆ array() [1/4]

template<typename TYPE, typename ALLOC>
original::array< TYPE, ALLOC >::array ( u_integer size = 0,
ALLOC alloc = ALLOC{} )
explicit

Constructs an empty array.

Parameters
sizeThe initial size of the array.
allocAllocator instance to use for memory management

Initializes the array with a given size, allocating memory for the array using the specified allocator and setting each element to its default value.

◆ array() [2/4]

template<typename TYPE, typename ALLOC>
original::array< TYPE, ALLOC >::array ( const std::initializer_list< TYPE > & lst)

Constructs an array from an initializer list.

Parameters
lstThe initializer list to initialize the array.

This constructor allows creating an array from a list of elements. The size of the array will be the size of the initializer list.

◆ array() [3/4]

template<typename TYPE, typename ALLOC>
original::array< TYPE, ALLOC >::array ( const array< TYPE, ALLOC > & other)

Copy constructor.

Parameters
otherThe array to copy from.

Initializes the array by copying the elements from another array. If ALLOC::propagate_on_container_copy_assignment is true, the allocator is also copied.

◆ array() [4/4]

template<typename TYPE, typename ALLOC>
original::array< TYPE, ALLOC >::array ( array< TYPE, ALLOC > && other)
noexcept

Move constructor.

Parameters
otherThe array to move from.

Moves the elements and resources from another array into this one, leaving the source array in a valid but unspecified state. If ALLOC::propagate_on_container_move_assignment is true, the allocator is also moved.

◆ ~array()

template<typename TYPE, typename ALLOC>
original::array< TYPE, ALLOC >::~array ( )
override

Destroys the array and releases its memory.

This destructor frees the memory allocated for the array.

Member Function Documentation

◆ begins()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::begins ( ) const
overridevirtual

Returns an iterator to the first element of the array.

Returns
An iterator to the first element.

Implements original::iterable< TYPE >.

◆ className()

template<typename TYPE, typename ALLOC>
std::string original::array< TYPE, ALLOC >::className ( ) const
nodiscardoverridevirtual

Returns the class name.

Returns
The class name as a string.

Reimplemented from original::printable.

◆ data()

template<typename TYPE, typename ALLOC>
TYPE & original::array< TYPE, ALLOC >::data ( ) const

Returns a reference to the first element of the array.

Returns
A reference to the first element of the array.

◆ ends()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::ends ( ) const
overridevirtual

Returns an iterator to the last element of the array.

Returns
An iterator to the last element.

Implements original::iterable< TYPE >.

◆ get()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::get ( integer index) const
overridevirtual

Retrieves an element at a specified index.

Parameters
indexThe index of the element to retrieve.
Returns
The element at the specified index.
Exceptions
outOfBoundErrorIf the index is out of bounds.

Implements original::serial< TYPE, ALLOC >.

◆ indexOf()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::indexOf ( const TYPE & e) const
overridevirtual

Finds the index of the specified element in the array.

Parameters
eThe element to find.
Returns
The index of the element, or the size of the array if the element is not found.

Implements original::serial< TYPE, ALLOC >.

◆ operator=() [1/2]

template<typename TYPE, typename ALLOC>
original::array< TYPE, ALLOC > & original::array< TYPE, ALLOC >::operator= ( array< TYPE, ALLOC > && other)
noexcept

Move assignment operator.

Parameters
otherThe array to move from.
Returns
The moved array.

Moves the elements and resources from another array into this one, leaving the source array in a valid but unspecified state. If ALLOC::propagate_on_container_move_assignment is true, the allocator is also moved.

◆ operator=() [2/2]

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::operator= ( const array< TYPE, ALLOC > & other)

Copy assignment operator.

Parameters
otherThe array to copy from.
Returns
The assigned array.

Copies the elements of another array into this array. If ALLOC::propagate_on_container_copy_assignment is true, the allocator is also copied.

◆ operator[]()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::operator[] ( integer index)
overridevirtual

Access an element at a specified index for modification.

Parameters
indexThe index of the element to access.
Returns
A reference to the element at the specified index.
Exceptions
outOfBoundErrorIf the index is out of bounds.

Implements original::serial< TYPE, ALLOC >.

◆ set()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::set ( integer index,
const TYPE & e )
overridevirtual

Sets the value of an element at the specified index.

Parameters
indexThe index of the element to set.
eThe value to assign to the element.
Exceptions
outOfBoundErrorIf the index is out of bounds.

Implements original::serial< TYPE, ALLOC >.

◆ size()

template<typename TYPE, typename ALLOC>
auto original::array< TYPE, ALLOC >::size ( ) const
nodiscardoverridevirtual

Returns the size of the array.

Returns
The number of elements in the array.

Implements original::container< TYPE, ALLOC >.


The documentation for this class was generated from the following file: