h1a4c3k's blog

By h1a4c3k, history, 6 weeks ago, In English

Today I read a blog that says: "In C++, comparator should return false if its arguments are equal." I don't really understand it (as I am a newbie to CP), can anyone explain for me about it? Btw, I makeup this piece of code: (g++14)

    #include <bits/stdc++.h>
    using namespace std;
     
    int main() {
    	int a = 1, b = 1;
    	if((a < b) == true) cout << 1;
    	else cout << 0;
    	return 0;
    }

I expected it to print out "0", but it print nothing instead. Can anyone explain those? Any help is appreciated, thanks to all of you!

PS: Sorry about my bad english

 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

Auto comment: topic has been updated by h1a4c3k (previous revision, new revision, compare).

»
6 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

When I run it in custom invocation, I get 0. The issue might be that you aren't flushing.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    I flushed it and it worked! Thanks for your answer :)

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

To extend the answer I am mostly sure that you have seen such statement in sorting-kinda blog. Then, indeed, when we use sort() with out custom comparator it should return false when arguments are equal.