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

Dynamic array container with amortized constant time operations. More...

#include <vector.h>

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

Classes

class  Iterator
 Random access iterator implementation for vector. More...
 

Public Member Functions

 vector (ALLOC alloc=ALLOC{})
 Constructs a vector with specified allocator.
 
template<typename... ARGS>
 vector (u_integer size, ALLOC alloc, ARGS &&... args)
 Constructs a vector with specified size and allocator, initializing elements with provided arguments.
 
 vector (const vector &other)
 Copy constructor for the vector.
 
 vector (const std::initializer_list< TYPE > &list)
 Constructs a vector from an initializer list.
 
 vector (const array< TYPE > &arr)
 Constructs a vector from an array.
 
vectoroperator= (const vector &other)
 Assignment operator for the vector.
 
 vector (vector &&other) noexcept
 Move constructor for the vector.
 
vectoroperator= (vector &&other) noexcept
 Move assignment operator for the vector.
 
u_integer size () const override
 Gets the size of the vector.
 
TYPE & data () const
 Gets a reference to the first element in the vector.
 
TYPE get (integer index) const override
 Gets an element at the specified index.
 
TYPE & operator[] (integer index) override
 Gets a reference to the element at the specified index.
 
void set (integer index, const TYPE &e) override
 Sets the element at the specified index.
 
u_integer indexOf (const TYPE &e) const override
 Finds the index of the first occurrence of the specified element.
 
void pushBegin (const TYPE &e) override
 Inserts an element at the beginning of the vector.
 
void push (integer index, const TYPE &e) override
 Inserts an element at the specified index in the vector.
 
void pushEnd (const TYPE &e) override
 Inserts an element at the end of the vector.
 
TYPE popBegin () override
 Removes and returns the first element in the vector.
 
TYPE pop (integer index) override
 Removes and returns the element at the specified index.
 
TYPE popEnd () override
 Removes and returns the last element in the vector.
 
Iteratorbegins () const override
 Gets an iterator to the beginning of the vector.
 
Iteratorends () const override
 Gets an iterator to the end of the vector.
 
std::string className () const override
 Gets the class name of the vector.
 
 ~vector () override
 Destructor for the vector.
 
- Public Member Functions inherited from original::baseList< TYPE, ALLOC >
virtual void add (const TYPE &e)
 Adds an element to the end of the list.
 
virtual TYPE remove (const TYPE &e)
 Removes an element from the list.
 
virtual void clear ()
 Removes all elements.
 
- 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.
 
- 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 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 adapter pointing to the beginning of the container.
 
iterAdaptor end ()
 Returns an iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor begin () const
 Returns a const iterator adapter pointing to the beginning of the container.
 
iterAdaptor end () const
 Returns a const iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor first ()
 Returns an iterator adapter pointing to the first element.
 
iterAdaptor last ()
 Returns an iterator adapter pointing to the last element.
 
iterAdaptor first () const
 Returns a const iterator adapter pointing to the first element.
 
iterAdaptor last () const
 Returns a const iterator adapter 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.
 

Friends

template<typename T, typename... ARGS>
vector< T > makeVector (u_integer size, ARGS &&... args)
 

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::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 Member Functions inherited from original::iterationStream< TYPE, DERIVED >
std::string elementsString () const
 Returns a string representation of the elements in the stream.
 
- 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::vector< TYPE, ALLOC >

Dynamic array container with amortized constant time operations.

Template Parameters
TYPEElement type stored in the vector
ALLOCAllocator type for memory management (default: allocator<TYPE>)

Features include:

  • Auto-resizing with centered memory allocation
  • Random access via operator[] with bounds checking
  • Bidirectional element insertion/removal
  • STL-style iterator support
  • Initializer list and array conversion

Memory management characteristics:

  • Uses the provided allocator for all memory operations
  • Grows exponentially (2x) when capacity is exceeded
  • Maintains centered memory layout for efficient front/back operations
  • Allocator propagation follows C++ standard rules

The ALLOC type must meet C++ allocator requirements and provide:

  • allocate()/deallocate() methods
  • construct()/destroy() methods
  • propagate_on_container_copy_assignment/move_assignment typedefs
Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

Constructor & Destructor Documentation

◆ vector() [1/6]

template<typename TYPE, typename ALLOC>
original::vector< TYPE, ALLOC >::vector ( ALLOC alloc = ALLOC{})
explicit

Constructs a vector with specified allocator.

Parameters
allocAllocator instance to use (default: default-constructed ALLOC)

Initializes the vector with default capacity (16 elements). The allocator will be used for all subsequent memory operations.

◆ vector() [2/6]

template<typename TYPE, typename ALLOC>
template<typename... ARGS>
original::vector< TYPE, ALLOC >::vector ( u_integer size,
ALLOC alloc,
ARGS &&... args )

Constructs a vector with specified size and allocator, initializing elements with provided arguments.

Template Parameters
ARGSVariadic template parameter pack for element construction arguments
Parameters
sizeThe initial number of elements in the vector
allocAllocator instance to use (default: default-constructed ALLOC)
argsArguments to forward to element constructors

This constructor:

  • Allocates storage for the specified number of elements
  • Constructs each element using the provided arguments
  • Maintains centered memory layout for efficient operations
Note
The vector's capacity will be automatically calculated to maintain optimal memory layout. All elements will be initialized with the same provided arguments.

◆ vector() [3/6]

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

Copy constructor for the vector.

Parameters
otherThe vector to copy from.

◆ vector() [4/6]

template<typename TYPE, typename ALLOC>
original::vector< TYPE, ALLOC >::vector ( const std::initializer_list< TYPE > & list)

Constructs a vector from an initializer list.

Parameters
listThe initializer list to construct the vector from.

◆ vector() [5/6]

template<typename TYPE, typename ALLOC>
original::vector< TYPE, ALLOC >::vector ( const array< TYPE > & arr)
explicit

Constructs a vector from an array.

Parameters
arrThe array to construct the vector from.

◆ vector() [6/6]

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

Move constructor for the vector.

Parameters
otherThe vector to move from.

Member Function Documentation

◆ begins()

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

Gets an iterator to the beginning of the vector.

Returns
An iterator to the beginning.

Implements original::iterable< TYPE >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ className()

template<typename TYPE, typename ALLOC>
auto original::vector< TYPE, ALLOC >::className ( ) const
nodiscardoverridevirtual

Gets the class name of the vector.

Returns
The class name as a string.

Reimplemented from original::iterationStream< TYPE, DERIVED >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ data()

template<typename TYPE, typename ALLOC>
auto original::vector< TYPE, ALLOC >::data ( ) const

Gets a reference to the first element in the vector.

Returns
A reference to the first element.
Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ ends()

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

Gets an iterator to the end of the vector.

Returns
An iterator to the end.

Implements original::iterable< TYPE >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ get()

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

Gets an element at the specified index.

Parameters
indexThe index of the element.
Returns
The element at the specified index.

Implements original::serial< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ indexOf()

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

Finds the index of the first occurrence of the specified element.

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

Implements original::serial< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ operator=() [1/2]

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

Assignment operator for the vector.

Parameters
otherThe vector to assign from.
Returns
A reference to this vector.
Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ operator=() [2/2]

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

Move assignment operator for the vector.

Parameters
otherThe vector to move from.
Returns
A reference to this vector.

◆ operator[]()

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

Gets a reference to the element at the specified index.

Parameters
indexThe index of the element.
Returns
A reference to the element at the specified index.

Implements original::serial< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ pop()

template<typename TYPE, typename ALLOC>
auto original::vector< TYPE, ALLOC >::pop ( integer index)
overridevirtual

Removes and returns the element at the specified index.

Parameters
indexThe index of the element to remove.
Returns
The removed element.

Implements original::baseList< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ popBegin()

template<typename TYPE, typename ALLOC>
auto original::vector< TYPE, ALLOC >::popBegin ( )
overridevirtual

Removes and returns the first element in the vector.

Returns
The removed element.

Implements original::baseList< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ popEnd()

template<typename TYPE, typename ALLOC>
auto original::vector< TYPE, ALLOC >::popEnd ( )
overridevirtual

Removes and returns the last element in the vector.

Returns
The removed element.

Implements original::baseList< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ push()

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

Inserts an element at the specified index in the vector.

Parameters
indexThe index to insert the element at.
eThe element to insert.

Implements original::baseList< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ pushBegin()

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

Inserts an element at the beginning of the vector.

Parameters
eThe element to insert.

Implements original::baseList< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ pushEnd()

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

Inserts an element at the end of the vector.

Parameters
eThe element to insert.

Implements original::baseList< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ set()

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

Sets the element at the specified index.

Parameters
indexThe index of the element to set.
eThe value to set.

Implements original::serial< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

◆ size()

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

Gets the size of the vector.

Returns
The number of elements in the vector.

Implements original::container< TYPE, ALLOC >.

Examples
D:/FrozenLemonTee/Arbeit/PracticeProject/original/src/core/vector.h.

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