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
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