Difference between upper bound and lower bound in stl

0 votes

I was looking at how the upper bound and lower bound algorithms operate in stl on these pages: lower bound, upper bound, and it's documented the same way on these pages: lower bound, upper bound, and it's documented the same way on these pages: lower bound, upper bound, and it' 

upper bound, lower bound

Looking at the code from the links, they appear to perform the same thing to me, with the exception of the following lines 

lower_bound (line 10):

if (*it<val) {                 // or: if (comp(*it,val)), for version (2)

upper_bound (line 10):

if (!(val<*it))                // or: if (!comp(val,*it)), for version (2) 

But isn't it true that inverting the compared elements and then comparing them to false is a double negative, and so they do the same thing?

Is there a distinction that I'm missing, or is this an error in the online documentation? 

If the latter, what is the proper procedure?

Jul 5 in C++ by Nicholas
• 5,300 points
41 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C++

0 votes
0 answers

Difference between set.upper_bound() and upper_bound(set.begin(), set.end()) stl

I discovered that set.upper bound() was quicker ...READ MORE

Jun 29 in C++ by Damon
• 4,960 points
10 views
0 votes
0 answers

What is the difference between std::list<std::pair> and std::map in C++ STL?

What distinguishes std::list<std::pair> from std::map? Does the ...READ MORE

1 day ago in C++ by Nicholas
• 5,300 points
2 views
0 votes
1 answer

What is the difference between public, private, and protected inheritance in C++?

To begin answering that question, let me characterise member accessors in my own terms.  If you already know this, proceed to the section "next:". I'm aware of three types of accessors: public, protected, and private. Let: class Base { public: ...READ MORE

answered Jul 11 in C++ by Damon
• 4,960 points
31 views
0 votes
0 answers

Difference between for loop and the range based loop in C++

The distinction between a for loop and ...READ MORE

Jul 11 in C++ by Nicholas
• 5,300 points
15 views
0 votes
1 answer

What is the difference between operator overloading and operator overriding in C++?

Some people use the latter word to ...READ MORE

answered Aug 2 in C++ by Damon
• 4,960 points
16 views
0 votes
0 answers

Difference between 'struct' and 'typedef struct' in C++?

In C++, is there any difference between: struct Foo ...READ MORE

Aug 8 in C++ by Nicholas
• 5,300 points
13 views
0 votes
1 answer

Syntax of priority queue

We must first include the queue header file in order to establish a priority queue in C++. #include <queue> Once we import this file, we ...READ MORE

answered May 31 in C++ by Damon
• 4,960 points
16 views
0 votes
1 answer

Sorting a vector of custom objects

A simple example using std::sort struct MyStruct { ...READ MORE

answered Jun 1 in C++ by Damon
• 4,960 points
42 views
0 votes
1 answer

lower_bound == upper_bound

Lower bound: the initial greater-or-equal element. Upper bound: ...READ MORE

answered Jun 21 in C++ by Damon
• 4,960 points
41 views
0 votes
1 answer

Comparison of C++ STL collections and C# collections

This is what I know Array - C ...READ MORE

answered Jun 9 in C# by rajiv
• 1,620 points
32 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP