lower_bound on only partly sorted array

Discussion in 'C++' started by Robert Fendt, Feb 14, 2010.

  1. Robert Fendt

    Robert Fendt Guest

    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
    Robert Fendt, Feb 14, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Fitzsimons

    Partly consistent web pages - How ?

    John Fitzsimons, Jul 23, 2004, in forum: HTML
    Replies:
    3
    Views:
    401
    Karl Groves
    Jul 23, 2004
  2. Maurizio Berlusconi

    recover a partly destroyed pickled structure

    Maurizio Berlusconi, Sep 25, 2004, in forum: Python
    Replies:
    1
    Views:
    277
    Mike C. Fletcher
    Sep 25, 2004
  3. Harlan Messinger
    Replies:
    1
    Views:
    379
  4. zaley
    Replies:
    18
    Views:
    442
    zaley
    Feb 25, 2008
  5. process

    Inheritance but only partly?

    process, Oct 2, 2008, in forum: Python
    Replies:
    12
    Views:
    485
    George Sakkis
    Oct 5, 2008
Loading...

Share This Page