I always thought that a "singular" iterator was one that has been default-initialised, and these could serve as comparable sentinel values of sorts:
typedef std::vector<Elem>::iterator I;
I start = I();
std::vector<Elem> container = foo();
for (I it = container.begin(), end = container.end(); it != end; ++it) {
if ((start == I()) && bar(it)) {
// Does something only the first time bar(it) is satisfied
// ...
start = it;
}
}
But this answer suggests not only that my definition of "singular" is wrong, but also that my comparison above is totally illegal.
Is it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…