Error in the C++ standard? - c++

This is a discussion on Error in the C++ standard? - c++ ; In section 23.1.2 table 69 upper and lower bound are defined like: a.lower_bound(k) iterator; logarithmic returns an iterator pointing to the first element with key not less than k a.upper_bound(k) iterator; logarithmic returns an iterator pointing to the first element ...

+ Reply to Thread
Results 1 to 6 of 6

Error in the C++ standard?

  1. Default Error in the C++ standard?

    In section 23.1.2 table 69 upper and lower bound are defined like:

    a.lower_bound(k) iterator; logarithmic
    returns an iterator pointing to the
    first element with key not less than k

    a.upper_bound(k) iterator; logarithmic
    returns an iterator pointing to the
    first element with key greater than k


    should "not less" in lower_bound not just be "less"? Or is it supposed
    to be interpreted as "greater than or equal"?


  2. Default Re: Error in the C++ standard?

    On 2007-06-13, desktop <fff@sss.com> wrote:
    > In section 23.1.2 table 69 upper and lower bound are defined like:
    >
    > a.lower_bound(k) iterator; logarithmic
    > returns an iterator pointing to the
    > first element with key not less than k
    >
    > a.upper_bound(k) iterator; logarithmic
    > returns an iterator pointing to the
    > first element with key greater than k
    >
    >
    > should "not less" in lower_bound not just be "less"? Or is it supposed
    > to be interpreted as "greater than or equal"?


    The standard is correct. Iterating through the range [lower_bound,
    upper_bound) should iterate through elements which "equal" k. "Not
    less" is, conceptually, "greater than or equal" so lower_bound is
    upper_bound when there is no matching element for k. This meets the
    logical requirement that [lower_bound, upper_bound) is empty. If
    lower_bound is not the same as upper_bound it implies that there is at
    least one element that matches k and [lower_bound, upper_bound)
    contains all such elements.

  3. Default Re: Error in the C++ standard?

    Charles Bailey wrote:
    > On 2007-06-13, desktop <fff@sss.com> wrote:
    >> In section 23.1.2 table 69 upper and lower bound are defined like:
    >>
    >> a.lower_bound(k) iterator; logarithmic
    >> returns an iterator pointing to the
    >> first element with key not less than k
    >>
    >> a.upper_bound(k) iterator; logarithmic
    >> returns an iterator pointing to the
    >> first element with key greater than k
    >>
    >>
    >> should "not less" in lower_bound not just be "less"? Or is it supposed
    >> to be interpreted as "greater than or equal"?

    >
    > The standard is correct. Iterating through the range [lower_bound,
    > upper_bound) should iterate through elements which "equal" k. "Not
    > less" is, conceptually, "greater than or equal" so lower_bound is
    > upper_bound when there is no matching element for k. This meets the
    > logical requirement that [lower_bound, upper_bound) is empty. If
    > lower_bound is not the same as upper_bound it implies that there is at
    > least one element that matches k and [lower_bound, upper_bound)
    > contains all such elements.


    Ok so:

    a.lower_bound(k) iterator; logarithmic
    returns an iterator pointing to the
    first element with key greater than or equal to k

    is as valid a definition, right?

  4. Default Re: Error in the C++ standard?

    desktop wrote:
    > Charles Bailey wrote:
    >> On 2007-06-13, desktop <fff@sss.com> wrote:
    >>> In section 23.1.2 table 69 upper and lower bound are defined like:
    >>>
    >>> a.lower_bound(k) iterator; logarithmic
    >>> returns an iterator pointing to the
    >>> first element with key not less than k
    >>>
    >>> a.upper_bound(k) iterator; logarithmic
    >>> returns an iterator pointing to the
    >>> first element with key greater than k
    >>>
    >>>
    >>> should "not less" in lower_bound not just be "less"? Or is it
    >>> supposed to be interpreted as "greater than or equal"?

    >>
    >> The standard is correct. Iterating through the range [lower_bound,
    >> upper_bound) should iterate through elements which "equal" k. "Not
    >> less" is, conceptually, "greater than or equal" so lower_bound is
    >> upper_bound when there is no matching element for k. This meets the
    >> logical requirement that [lower_bound, upper_bound) is empty. If
    >> lower_bound is not the same as upper_bound it implies that there is at
    >> least one element that matches k and [lower_bound, upper_bound)
    >> contains all such elements.

    >
    > Ok so:
    >
    > a.lower_bound(k) iterator; logarithmic
    > returns an iterator pointing to the
    > first element with key greater than or equal to k
    >
    > is as valid a definition, right?


    yes.


    Regards,

    Zeppe

  5. Default Re: Error in the C++ standard?

    On 2007-06-13, desktop <fff@sss.com> wrote:
    >
    > Ok so:
    >
    > a.lower_bound(k) iterator; logarithmic
    > returns an iterator pointing to the
    > first element with key greater than or equal to k
    >
    > is as valid a definition, right?


    It should be "greater than or equivalent to k" to be consistent with
    the language used in that section of the standard. As it mentions the
    key type could have an operator== but this is irrelevant for the
    purposes of lower_bound, upper_bound, etc. Equivalence of k1 and k2
    means that neither one sorts before the other according to the
    container's ordering relation.

    I suspect that this is why they chose the working "not less than" in
    this case.


  6. Default Re: Error in the C++ standard?

    "desktop" <fff@sss.com> wrote in message
    news:f4okjk$aad$1@news.net.uni-c.dk...

    > Ok so:


    > a.lower_bound(k) iterator; logarithmic
    > returns an iterator pointing to the
    > first element with key greater than or equal to k


    > is as valid a definition, right?


    Well, sort of. The problem is that "less" is the only relation that is
    required to be defined in order for lower_bound to work, so the behavior of
    lower_bound really should be described in terms of "less", not "greater than
    or equal".



+ Reply to Thread

Similar Threads

  1. Replies: 5
    Last Post: 12-05-2007, 07:21 PM
  2. Replies: 3
    Last Post: 06-15-2007, 03:34 PM
  3. Error when Recognizing Text Using OCR - Adobe 7 Standard
    By Application Development in forum Adobe Acrobat
    Replies: 0
    Last Post: 02-07-2007, 09:53 PM
  4. Asymptotic Standard Error
    By Application Development in forum Graphics
    Replies: 2
    Last Post: 01-08-2007, 07:09 PM
  5. Grammar Error in Standard?
    By Application Development in forum c++
    Replies: 6
    Last Post: 07-31-2006, 12:13 AM