#include <mywheel/array_like.hpp>
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.
Public types
- class Iterator
Constructors, destructors, conversion operators
- ShiftArray()
- ShiftArray(const std::vector<T>& lst) explicit
- ShiftArray(std::vector<T>&& lst) explicit
Public functions
- void set_start(size_t start)
- 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.