hybrid implementation of an array and stack.
More...
#include <indexed-stack.hpp>
|
| void | delete_range (size_t start, size_t end) noexcept |
| | frees elements on the stack that are in certain range.
|
| |
| void | resize (size_t new_capacity) |
| | updates the capacity of the stack based on a size.
|
| |
|
| T * | data |
| | pointer to the bottom element of the stack.
|
| |
| size_t | size |
| | number of the elements on the stack.
|
| |
| size_t | capacity |
| | allocated space for the stack.
|
| |
template<typename T>
class indexed_stack< T >
hybrid implementation of an array and stack.
- Template Parameters
-
| T | - type of the data stored on the stack. |
◆ indexed_stack() [1/3]
creates the instance of the indexed_stack.
preallocates the memory for DEFAULT_STACK_CAPACITY elements; default size 0.
◆ ~indexed_stack()
destroys the indexed_stack object.
frees all elements on the stack, frees the memory allocated for the stack.
◆ indexed_stack() [2/3]
deleted copy constructor.
◆ indexed_stack() [3/3]
constructs new indexed_stack from an existing one.
- Parameters
-
moves ownership of the data, size and capacity from other to this.
◆ begin() [1/2]
getter for the bottom element of the stack.
- Returns
- the pointer to the bottom element of the stack.
◆ begin() [2/2]
getter for the bottom element of the stack.
- Returns
- the const pointer to the bottom element of the stack.
◆ delete_range()
template<typename T >
| void indexed_stack< T >::delete_range |
( |
size_t |
start, |
|
|
size_t |
end |
|
) |
| |
|
inlineprivatenoexcept |
frees elements on the stack that are in certain range.
- Parameters
-
| start | - starting index. |
| end | - ending index (excluded). |
◆ empty()
checks if the stack is empty.
- Returns
- true if stack is empty; false otherwise.
◆ end() [1/2]
getter for the end of the stack.
- Returns
- the pointer to the end of the stack.
◆ end() [2/2]
getter for the end of the stack.
- Returns
- the const pointer to the end of the stack.
◆ get_capacity()
getter for the capacity of the stack.
- Returns
- capacity of the stack.
◆ get_size()
getter for the size of the stack.
- Returns
- number of elements on the stack.
◆ operator=() [1/2]
deleted assignment operator.
◆ operator=() [2/2]
constructs new indexed_stack by assigning it an existing one.
- Parameters
-
moves ownership of the data, size and capacity from other to this.
◆ operator[]() [1/2]
operator for direct indexing.
- Parameters
-
| i | - position of the element on the stack; calculated from the bottom. |
- Returns
- reference to an element on the stack.
- Exceptions
-
| std::out_of_range | when index is bigger than or equal to size. |
◆ operator[]() [2/2]
operator for direct indexing.
- Parameters
-
| i | - position of the element on the stack; calculated from the bottom. |
- Returns
- const reference to an element on the stack.
- Exceptions
-
| std::out_of_range | when index is bigger than or equal to size. |
◆ peek() [1/2]
getter for the element on the top of the stack.
- Returns
- the reference to the top element on the stack.
- Exceptions
-
| std::out_of_range | when stack is empty. |
◆ peek() [2/2]
getter for the element on the top of the stack.
- Returns
- the const reference to the top element on the stack.
- Exceptions
-
| std::out_of_range | when stack is empty. |
◆ pop()
removes the element from the top of the stack.
if 75% of capacity is free, stack is reallocated and capacity is half the previous capacity; doesn't go below DEFAULT_STACK_CAPACITY.
- Exceptions
-
| std::out_of_range | when stack is empty. |
◆ push()
template<typename T >
template<typename TT >
requires std::is_constructible_v<T, TT&&>
pushes new value to the top of the stack.
- Template Parameters
-
| TT | - Value forwarding type. |
- Parameters
-
| value | - const reference object being added to the stack. |
if size reaches capacity, capacity is doubled.
◆ resize()
updates the capacity of the stack based on a size.
- Parameters
-
| new_capacity | - new capacity of the stack, can't go below DEFAULT_STACK_CAPACITY. |
- Exceptions
-
| std::bad_alloc | when ::operator new fails to allocate memory. |
| std::invalid_argument | if new_capacity is below DEFAULT_STACK_CAPACITY |
◆ capacity
allocated space for the stack.
◆ data
pointer to the bottom element of the stack.
◆ size
number of the elements on the stack.
The documentation for this class was generated from the following file: