Share your repls and programming experiences

← Back to all posts
Doubt
Pranav0810 (0)

Couldn't understand how comparators really work...especially in this code where it "compare" fn. (used in lower_bound function) has 2 arguments. Howcome?

Commentshotnewtop
DynamicSquid (1968)

a <= b

if a is smaller or equal to b, return true
if a is not smaller or equal to b, return false

Or think of it as this:

if (a <= b)
  return true;
else
  return false

Hope this helps!

Pranav0810 (0)

@DynamicSquid In my code, what arguments are being taken instead of 'a' and 'b' each time compare function is called in lower_bound fn.

Isn't compare function a functor?
Thanks!

RayvelArjoon (68)

@Pranav0810 Nothing is being compared because they haven't been assigned values.

RayvelArjoon (68)

Comparison operators include: ==, <, >, >=, <=

Comparison operators are used in conditional statements.

int main() {
  #include <iostream>
  using namespace std;
  int num = 2;
  int num2 = 6;
  if(num >= num2){
    std::cout << true;
  }else{
    std::cout << false;
  }
}

This statement means that if variable num is greater than variable num2, execute the character output true. Otherwise, output false;

Pranav0810 (0)

@RayvelArjoon In my code, what arguments are being taken instead of 'a' and 'b' each time compare function is called in lower_bound fn.

Isn't compare function a functor?