Strange Behaviour with std::set comparators
Difference between en1 and en2, changed 70 character(s)
~~~~~↵
#include <bits/stdc++.h>↵

using namespace std;↵

#define endl '\n'↵
#define int long long↵

const int N = 1e5 + 20;↵

int m[N];↵

struct comp {↵
    bool operator() (const pair <int , int> &lhs, const pair <int , int> &rhs) const {↵
        return lhs.first > rhs.first;↵
    }↵
};↵


int32_t main()↵
{↵
    ios_base :: sync_with_stdio(0);↵
    cin.tie(0);↵

    set <pair <int , int> , comp> s;↵
    s.insert({1 , 1});↵
    s.insert({1 , 2});↵
    s.insert({1 , 3});↵
    s.insert({1 , 4});↵

    for(auto x : s)↵
        cout << 
"(" << x.first << " ," << x.second << ")  ";↵
    cout << 
endl;↵
    return 0;↵
}↵


~~~~~↵

I expected the above code to print :↵
1 1↵
1 2↵
1 3↵
1 4↵
(1,4)  (1,3)  (1,2)  (1,1)
But it only prints :↵

1 1(1,1)

However
, that works fine without the comparator.↵
Why is this strange thing happening?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English wannbegood 2020-08-07 23:48:52 70
en1 English wannbegood 2020-08-07 23:44:22 835 Initial revision (published)