Is it possible to get a const iterator from a vector that can only iterate a certain range of the vector before being invalidated?
For example if I have a vector of 10 elements, I want to return an iterator of elements 4 to 7.
pseudo-code:
int main()
{
std::vector<int> vector = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto iterator = GetRangedIterator(vector, 4, 7)
for (const int& num : iterator)
print num; // 4, 5, 6, 7
}
Aucun commentaire:
Enregistrer un commentaire