template<typename T>
ShiftArray class
Shift Array.
| Template parameters | |
|---|---|
| T | |
The ShiftArray class is a template class that extends a given container type. It allows accessing elements of the container using shifted indices. The shift value is set using the set_start method, and the shifted indices are calculated by subtracting the shift value from the original index. The class provides operator[] overloads to access elements using shifted indices.
Original indices: [0] [1] [2] [3] [4] [5] Array content: [A] [B] [C] [D] [E] [F] After set_start(2): Accessible range: [0] [1] [2] [3] <-- These map to [C] [D] [E] [F] Shifted indices: [2] [3] [4] [5] <-- Internal indices
Public types
- class Iterator
Constructors, destructors, conversion operators
- ShiftArray(const std::vector<T>& lst) explicit
Public functions
- auto operator[](size_t key) const -> const T&
- auto operator[](size_t key) -> T&
- auto begin() const -> Iterator
- auto end() const -> Iterator
- auto size() const -> size_t
Function documentation
template<typename T>
ShiftArray<T>:: ShiftArray(const std::vector<T>& lst) explicit
| Parameters | |
|---|---|
| lst in | The parameter "lst" is a vector of type T, which is the type of elements stored in the vector. |
The ShiftArray function takes a vector as input and initializes the start variable to 0 and the lst variable to the input vector.
template<typename T>
const T& ShiftArray<T>:: operator[](size_t key) const
| Returns | The operator[] is returning a constant reference to an element in the list. |
|---|
The above function is an overloaded operator[] that returns a constant reference to an element in a list.
template<typename T>
T& ShiftArray<T>:: operator[](size_t key)
| Returns | The T& operator[] function returns a reference to an element in the lst vector, which is accessed using the key parameter. |
|---|
The function overloads the subscript operator to access elements in a list-like container.
template<typename T>
size_t ShiftArray<T>:: size() const
| Returns | the size of the list (lst) minus the starting index (start). |
|---|
The function returns the size of a list, excluding a specified starting index.