The question is pretty self explanatory I think.
If I have a std::vector<int> v = {1,2,3}
, are v.end() - 1
or v.end()--
valid expressions?
I know that most iterators support it, but the question is, is it defined behavior? Unfortunately it is really hard to find information about it. Isn't there an iterator specification? The standard itself seems to be very vague about it or I just missed the passage that defines them on such a low level.
I need this for writing my own library. Some more advanced lazy evaluation iterators are very difficult to write under the light of v.end()--
being a valid expression, since the "end" is not really known without iterating through it or tracking the "end" within the iterator itself which makes the whole a LOT more complex, since you need to special case almost everything inside the iterator implementation.
The fact that v.end()--
causes such headaches for me made me wonder if it is even allowed ;). Unfortunately, the "end" must be extremely efficient due to frequent usage patterns, so it must be constant time, that's what makes things so difficult here.
Aucun commentaire:
Enregistrer un commentaire