I have a vector. What I want to do is store a value at the first index of the vector. However, this value is for errors and so I would like to refer to this value like vector_ [-1]
. How do I go about with this?
I came up with one solution. What I'm doing is creating a new vector and assigning the new vector to this vector.
vector_.resize(required_size+1);
vector_ = std::vector<T> (vector_.begin()+1,vector_.end());
At this point could I legally use vector_[-1]
? If not, please help me with other solutions.
EDIT
I found a workaround. Though its not vectors with negative indexing, I'm using a pointer to the second member of the vector so when I do ptr[-1]
, it points to the first element of the vector.