§ C++ lower_bound, upper_bound API


I never remember what precisely lower_bound returns, so this is me collecting this information in a way that makes sense to me. The API docs say
Returns an iterator pointing to the first element in the range [first,last)
which does not compare less than val.


In contrast, upper_bound says:
Returns an iterator pointing to the first element in the range [first,last) which compares greater than val.


§ Pictorially


If we have a range:
<<<<<<< ======= >>>>>>>>
        |     |
        L     R


<<<<<<< ======= >>>>>>>>
        L     R |
        lower   upper

§ Traversals



How to think about which one we want? This about it as lowerbound shifts iterators towards the left, and upperbound shifts iterators to right.

§ equal_range