lower_bound on only partly sorted array

R

Robert Fendt

Hi,

does anyone know if std::lower_bound and upper_bound are
guaranteed to be reasonably well-behaved even if the input list
is not completely sorted?

E.g., if I get input like this:
int myvals[] = {1, 4, 5, 7, 2, 3, 8, 9};

is it still 'legal' to use std::lower_bound(4) on it (granted it
is not guaranteed whether the result will be 1 or 6)? It would
not matter which value were returned, as long as it is a legal
array index.

The background is thus: if I get illegal input data, I cannot
provide sensible output anyway. But I would like to make sure the
program does not crash, even if the calculation result is
nonsense. Performance is an issue, so sorting myself and thus
checking the input for monotonicity (throwing an exception if
input is not monotonic) would only be an acceptable option in
debug build.

Regards,
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top