0

I lately had some trouble with .lower_bound() until i found out that it returns an iterator to the past-the-end element if no value fits the argument. The same for .end(), which points to the past-the-end entry.

What's the use of the past-the-end element and why does it not just points to the very last element of the vector? E.g. to the element that .back() returns?

dani
  • 3,677
  • 4
  • 26
  • 60
  • 3
    Because `back()` can be a valid element, so it cannot mean "no element found"? The past-the-end element allows using simple half-open-on-right ranges of the form [first, one-past-last). Those conceptually can easily express empty sets: [x, x) is an empty set/range. – dyp Oct 06 '14 at 20:44
  • 1
    Two words: empty sequence. – BartoszKP Oct 06 '14 at 20:45
  • 1
    Try to divide a range into two subranges. [a, b) = [a, c) + [c, b). Notice identical types (half-open). Try to do that with [a, b]. It doesn't work. – user515430 Oct 06 '14 at 22:20

0 Answers0