std::lower_bound is called on a range that is not partitioned with respect to the searched value. What is the outcome?
Correct answer
C. Undefined behaviour, because the range must be partitioned for the search
11 views
C. Undefined behaviour, because the range must be partitioned for the search
11 views
The binary-search family requires the range to be partitioned with respect to the value and predicate: every element for which the predicate holds must precede every element for which it does not. Violating that precondition is undefined behaviour rather than a defined but disappointing result, so lower_bound may return any position at all. A range sorted by the same comparison does satisfy the condition for the default less-than predicate.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.