upper_bound vs. lower_bound

Posted on 2007-10-17
Last Modified: 2012-05-05
Is it true that there is no practical difference between std::lower_bound and std::upper_bound if the sorted range has all unique values?
Question by:chsalvia
    LVL 53

    Accepted Solution

    upper_bound returns the first value higher than a given value in a sorted series.
    lower_bound returns the first value which is not less than a given value in a sorted series


    So, in other words, lower_bound is equivalent to >=, while upper_bound is equivalent to >. ie. they're not exactly the same.
    LVL 86

    Assisted Solution

    No. See the code samples and the output at and (scroll down a bit for the examples on both pages)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now