|
DSA - Data Structures and Algorithms
|
Implements Vector class template for dynamic size container. More...
#include <vector.h>
Public Types | |
| using | value_type = T |
| Alias for data type used in class. | |
| using | allocator_type = std::allocator<value_type> |
| Alias for memory allocator. | |
| using | size_type = std::size_t |
| Alias for size type used in class. | |
| using | difference_type = std::ptrdiff_t |
| Alias for pointer difference type. | |
| using | pointer = T* |
| Alias for pointer to data type used in class. | |
| using | const_pointer = const T* |
| Alias for const pointer to data type used in class. | |
| using | reference = T& |
| Alias for reference to data type used in class. | |
| using | const_reference = const T& |
| Alias for const reference to data type used in class. | |
| using | iterator = T* |
| Alias for iterator to data type used in class. | |
| using | const_iterator = const T* |
| Alias for const iterator to data type used in class. | |
| using | reverse_iterator = std::reverse_iterator<iterator> |
| Alias for reverse_iterator to data type used in class. | |
| using | const_reverse_iterator = std::reverse_iterator<const_iterator> |
| Alias for const reverse_iterator to data type used in class. | |
Public Member Functions | |
| constexpr | Vector () |
| Construct a new Vector object. | |
| constexpr | Vector (size_type count) |
Construct a new Vector object of size count, using default value of type T. | |
| constexpr | Vector (size_type count, const T &value) |
Construct a new Vector object of size count, using provided value of type T. | |
| template<typename InputIt> requires std::input_iterator<InputIt> | |
| constexpr | Vector (InputIt first, InputIt last) |
Construct a new Vector object using elements from range [ first , last ) | |
| constexpr | Vector (const Vector< T > &other) |
| Construct a new Vector object using copy constructor. | |
| constexpr | Vector (Vector< T > &&other) noexcept |
| Construct a new Vector object using move constructor. | |
| constexpr | Vector (std::initializer_list< T > init_list) |
| Construct a new Vector object using initializer list. | |
| ~Vector () | |
| Destroy the Vector object. | |
| constexpr auto | operator= (const Vector< T > &other) -> Vector< T > & |
| Assign Vector object using copy assignment. | |
| constexpr auto | operator= (Vector< T > &&other) noexcept -> Vector< T > & |
| Assign Vector object using move assignment. | |
| constexpr auto | operator= (std::initializer_list< T > init_list) -> Vector< T > & |
Assign Vector object from init_list elements. | |
| constexpr void | assign (size_type count, const T &value) |
Function assign count , elements of value to Vector object. | |
| template<typename InputIt> requires std::input_iterator<InputIt> | |
| constexpr void | assign (InputIt first, InputIt last) |
Function assign elements from range [ first , last ) to Vector object. | |
| constexpr void | assign (std::initializer_list< T > init_list) |
Function assign values of init_list to Vector object. | |
| constexpr auto | get_allocator () const -> allocator_type |
| Get the allocator object. | |
| constexpr auto | at (size_type pos) -> reference |
Returns a reference to Vector element at pos index. If pos is outside of container range, an exception std::out_of_range is thrown. | |
| constexpr auto | at (size_type pos) const -> const_reference |
Returns a const_reference to Vector element at pos index. If pos is outside of container range, an exception std::out_of_range is thrown. | |
| constexpr auto | operator[] (size_type pos) -> reference |
Returns a reference to Vector element at pos index. If pos is outside of container range, undefined behaviour occurs. | |
| constexpr auto | operator[] (size_type pos) const -> const_reference |
Returns a const_reference to Vector element at pos index. If pos is outside of container range, undefined behaviour occurs. | |
| constexpr auto | front () -> reference |
| Returns reference to first Arary element. | |
| constexpr auto | front () const -> const_reference |
| Returns const_reference to first Arary element. | |
| constexpr auto | back () -> reference |
| Returns reference to last Arary element. | |
| constexpr auto | back () const -> const_reference |
| Returns const_reference to last Arary element. | |
| constexpr auto | data () noexcept -> pointer |
| Returns pointer to underlying data container. | |
| constexpr auto | data () const noexcept -> const_pointer |
| Returns const_pointer to underlying data container. | |
| constexpr auto | begin () noexcept -> iterator |
| Returns iterator to first element. | |
| constexpr auto | begin () const noexcept -> const_iterator |
| Returns const_iterator to first element. | |
| constexpr auto | cbegin () const noexcept -> const_iterator |
| Returns const_iterator to first element. | |
| constexpr auto | end () noexcept -> iterator |
| Returns iterator past last element of underlaying data structure. | |
| constexpr auto | end () const noexcept -> const_iterator |
| Returns const_iterator past last element of underlaying data structure. | |
| constexpr auto | cend () const noexcept -> const_iterator |
| Returns const_iterator past last element of underlaying data structure. | |
| constexpr auto | rbegin () -> reverse_iterator |
| Returns reverse_iterator to the first element of reversed underlaying data structure. | |
| constexpr auto | rbegin () const -> const_reverse_iterator |
| Returns const_reverse_iterator to the first element of reversed underlaying data structure. | |
| constexpr auto | crbegin () const noexcept -> const_reverse_iterator |
| Returns const_reverse_iterator to the first element of reversed underlaying data structure. | |
| constexpr auto | rend () -> reverse_iterator |
| Returns reverse_iterator past the last element of reversed underlaying data structure. | |
| constexpr auto | rend () const -> const_reverse_iterator |
| Returns const_reverse_iterator past the last element of reversed underlaying data structure. | |
| constexpr auto | crend () const noexcept -> const_reverse_iterator |
| Returns const_reverse_iterator past the last element of reversed underlaying data structure. | |
| constexpr auto | empty () const -> bool |
| Checks if container has elements. | |
| constexpr auto | size () const noexcept -> size_type |
| Returns number of elements in container. | |
| constexpr auto | max_size () const noexcept -> size_type |
| Returns maximum number of elements container can hold. | |
| constexpr void | reserve (size_type new_cap) |
| Increase the capacity of the container. | |
| constexpr auto | capacity () -> size_type |
| Returns the number of elements allocated for container. | |
| constexpr void | shrink_to_fit () |
| Request to remove of unused capacity. | |
| constexpr void | clear () |
| Erases all elements of the container Does not affect container capacity. | |
| constexpr auto | insert (const_iterator pos, const T &value) -> iterator |
Insert a copy of value before pos. | |
| constexpr auto | insert (const_iterator pos, T &&value) -> iterator |
Insert value before pos possibly using move semantics. | |
| constexpr auto | insert (const_iterator pos, size_type count, const T &value) -> iterator |
Insert count copies of value before pos. | |
| template<typename InputIt> requires std::input_iterator<InputIt> | |
| constexpr auto | insert (const_iterator pos, InputIt first, InputIt last) -> iterator |
Insert elements from range [ first , last ) befor pos. | |
| constexpr auto | insert (const_iterator pos, std::initializer_list< T > init_list) -> iterator |
Insert constent of init_list before pos. | |
| template<typename... Args> | |
| constexpr auto | emplace (const_iterator pos, Args &&... args) -> iterator |
Insert new element into the container before pos. | |
| template<typename... Args> | |
| constexpr auto | emplace_back (Args &&... args) -> reference |
Appends a copy of value at the end of the container. | |
| constexpr auto | erase (iterator pos) -> iterator |
| Erases specified element from the container. | |
| constexpr auto | erase (const_iterator pos) -> iterator |
| Erases specified element from the container. | |
| constexpr auto | erase (iterator first, iterator last) -> iterator |
Erases elements in range [ first , last ) from the container. | |
| constexpr auto | erase (const_iterator first, const_iterator last) -> iterator |
Erases elements in range [ first , last ) from the container. | |
| constexpr void | push_back (const T &value) |
Appends a copy of value at the end of the container. | |
| constexpr void | push_back (T &&value) |
Appends a copy of value at the end of the container. | |
| constexpr void | pop_back () |
| Removes the last element of the container. | |
| constexpr void | resize (size_type count) |
Resizez the container to contain count elements if count is equal to current size, does nothing if current size is greater than count , container size is reduced if current size is less than count , additional copies of T() are appended. | |
| constexpr void | resize (size_type count, const value_type &value) |
Resizes the container to contain count elements if count is equal to current size, does nothing if current size is greater than count , container size is reduced if current size is less than count , additional copies of value are appended. | |
| constexpr void | swap (Vector< T > &other) noexcept |
Exchanges content of current container with other container. | |
Implements Vector class template for dynamic size container.
| T | type of data stored in container |
add non-member specialized erase function
add non-member specialized erase_if function
| using dsa::Vector< T >::allocator_type = std::allocator<value_type> |
| using dsa::Vector< T >::const_iterator = const T* |
| using dsa::Vector< T >::const_pointer = const T* |
| using dsa::Vector< T >::const_reference = const T& |
| using dsa::Vector< T >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Alias for const reverse_iterator to data type used in class.
| using dsa::Vector< T >::difference_type = std::ptrdiff_t |
| using dsa::Vector< T >::iterator = T* |
| using dsa::Vector< T >::pointer = T* |
| using dsa::Vector< T >::reference = T& |
| using dsa::Vector< T >::reverse_iterator = std::reverse_iterator<iterator> |
Alias for reverse_iterator to data type used in class.
| using dsa::Vector< T >::size_type = std::size_t |
| using dsa::Vector< T >::value_type = T |
|
constexpr |
|
constexpr |
Construct a new Vector object of size count, using provided value of type T.
| [in] | count | element count |
| [in] | value | value for all elements |
Definition at line 725 of file vector.h.
|
constexpr |
Construct a new Vector object using elements from range [ first , last )
| InputIt |
| [in] | first | element defining range of elements to insert |
| [in] | last | element definig range of elements to insert |
Definition at line 736 of file vector.h.
|
constexpr |
Construct a new Vector object using copy constructor.
| [in] | other | Vector object of type T |
Definition at line 744 of file vector.h.
|
constexprnoexcept |
Construct a new Vector object using move constructor.
Content of other object will be taken by constructed object
| [in,out] | other | Vector object of type T |
Definition at line 754 of file vector.h.
|
constexpr |
| dsa::Vector< T >::~Vector | ( | ) |
|
constexpr |
Function assign elements from range [ first , last ) to Vector object.
| InputIt |
| [in] | first | element defining range of elements to insert |
| [in] | last | element definig range of elements to insert |
Definition at line 844 of file vector.h.
|
constexpr |
Function assign count , elements of value to Vector object.
| [in] | count | new size of the container |
| [in] | value | value to initialize elements of the container with |
|
constexpr |
Function assign values of init_list to Vector object.
| [in] | init_list | initializer list of values of type T |
|
nodiscardconstexpr |
Returns a reference to Vector element at pos index. If pos is outside of container range, an exception std::out_of_range is thrown.
| [in] | pos | index of element to return |
pos index Definition at line 881 of file vector.h.
|
nodiscardconstexpr |
Returns a const_reference to Vector element at pos index. If pos is outside of container range, an exception std::out_of_range is thrown.
| [in] | pos | index of element to return |
pos index Definition at line 893 of file vector.h.
|
nodiscardconstexpr |
|
nodiscardconstexpr |
Returns const_reference to last Arary element.
Definition at line 940 of file vector.h.
|
nodiscardconstexprnoexcept |
Returns const_iterator to first element.
Definition at line 967 of file vector.h.
|
nodiscardconstexprnoexcept |
|
constexpr |
|
nodiscardconstexprnoexcept |
Returns const_iterator to first element.
Definition at line 973 of file vector.h.
|
nodiscardconstexprnoexcept |
Returns const_iterator past last element of underlaying data structure.
Definition at line 993 of file vector.h.
|
constexpr |
|
nodiscardconstexprnoexcept |
Returns const_reverse_iterator to the first element of reversed underlaying data structure.
Definition at line 1012 of file vector.h.
|
nodiscardconstexprnoexcept |
Returns const_reverse_iterator past the last element of reversed underlaying data structure.
Definition at line 1030 of file vector.h.
|
nodiscardconstexprnoexcept |
Returns const_pointer to underlying data container.
Definition at line 954 of file vector.h.
|
nodiscardconstexprnoexcept |
|
constexpr |
Insert new element into the container before pos.
| Args |
| [in] | pos | iterator before which new element will be inserted |
| [in] | args | arguments to forward to the constructor of the element |
pos remains valid if reallocation occurs, all iterators and references are invalidated Definition at line 1152 of file vector.h.
|
constexpr |
Appends a copy of value at the end of the container.
| Args |
| [in] | args | arguments to forward to the constructor of the element |
Definition at line 1164 of file vector.h.
|
nodiscardconstexpr |
|
nodiscardconstexprnoexcept |
Returns const_iterator past last element of underlaying data structure.
Definition at line 986 of file vector.h.
|
nodiscardconstexprnoexcept |
Returns iterator past last element of underlaying data structure.
Definition at line 979 of file vector.h.
|
constexpr |
Erases elements in range [ first , last ) from the container.
| [in] | first | element defining range of elements to insert |
| [in] | last | element definig range of elements to insert |
first does not need to be dereferencable iterators and references at and after first are invalidated Definition at line 1203 of file vector.h.
|
constexpr |
Erases specified element from the container.
| [in] | pos | iterator to the element to remove |
pos must be valid and dereferencable iterators and references at and after pos are invalidated Definition at line 1191 of file vector.h.
|
constexpr |
Erases elements in range [ first , last ) from the container.
| [in] | first | element defining range of elements to insert |
| [in] | last | element definig range of elements to insert |
first does not need to be dereferencable iterators and references at and after first are invalidated Definition at line 1197 of file vector.h.
|
constexpr |
Erases specified element from the container.
| [in] | pos | iterator to the element to remove |
pos must be valid and dereferencable iterators and references at and after pos are invalidated
|
nodiscardconstexpr |
|
nodiscardconstexpr |
Returns const_reference to first Arary element.
Definition at line 926 of file vector.h.
|
nodiscardconstexpr |
Get the allocator object.
Definition at line 875 of file vector.h.
|
constexpr |
Insert a copy of value before pos.
| [in] | pos | iterator before which new element will be inserted |
| [in] | value | element to insert into container |
Definition at line 1086 of file vector.h.
|
constexpr |
Insert elements from range [ first , last ) befor pos.
| InputIt |
| [in] | pos | iterator before which new element will be inserted |
| [in] | first | element defining range of elements to insert |
| [in] | last | element definig range of elements to insert |
pos if no element was insertedpos remains valid if reallocation occurs, all iterators and references are invalidated
|
constexpr |
Insert count copies of value before pos.
| [in] | pos | iterator before which new element will be inserted |
| [in] | count | number of copies to insert into container |
| [in] | value | element to insert into container |
pos if no element was insertedpos remains valid if reallocation occurs, all iterators and references are invalidated Definition at line 1098 of file vector.h.
|
constexpr |
Insert constent of init_list before pos.
| [in] | pos | iterator before which new element will be inserted |
| [in] | init_list | container to insert befor pos |
pos if no element was insertedpos remains valid if reallocation occurs, all iterators and references are invalidated Definition at line 1134 of file vector.h.
|
constexpr |
Insert value before pos possibly using move semantics.
| [in] | pos | iterator before which new element will be inserted |
| [in] | value | element to insert into container |
|
nodiscardconstexprnoexcept |
Returns maximum number of elements container can hold.
Definition at line 1048 of file vector.h.
|
constexpr |
|
constexpr |
|
constexprnoexcept |
|
nodiscardconstexpr |
Returns a reference to Vector element at pos index. If pos is outside of container range, undefined behaviour occurs.
| [in] | pos | index of element to return |
Definition at line 905 of file vector.h.
|
nodiscardconstexpr |
Returns a const_reference to Vector element at pos index. If pos is outside of container range, undefined behaviour occurs.
| [in] | pos | index of element to return |
Definition at line 912 of file vector.h.
|
constexpr |
|
constexpr |
|
constexpr |
Appends a copy of value at the end of the container.
| [in] | value | the value of the element to append |
Definition at line 1237 of file vector.h.
|
nodiscardconstexpr |
Returns reverse_iterator to the first element of reversed underlaying data structure.
Definition at line 1000 of file vector.h.
|
nodiscardconstexpr |
Returns const_reverse_iterator to the first element of reversed underlaying data structure.
|
nodiscardconstexpr |
Returns reverse_iterator past the last element of reversed underlaying data structure.
|
nodiscardconstexpr |
Returns const_reverse_iterator past the last element of reversed underlaying data structure.
|
constexpr |
Increase the capacity of the container.
| [in] | new_cap | new capacity of container, new number of elements the container can store |
Definition at line 1054 of file vector.h.
|
constexpr |
Resizez the container to contain count elements if count is equal to current size, does nothing if current size is greater than count , container size is reduced if current size is less than count , additional copies of T() are appended.
| [in] | count | new size of the container |
Definition at line 1260 of file vector.h.
|
constexpr |
Resizes the container to contain count elements if count is equal to current size, does nothing if current size is greater than count , container size is reduced if current size is less than count , additional copies of value are appended.
| [in] | count | new size of the container |
| [in] | value | the value to initialize the new element with |
Definition at line 1266 of file vector.h.
|
constexpr |
|
nodiscardconstexprnoexcept |
|
constexprnoexcept |