[Help!] How to implement sets and maps of self defined structs with custom comparator in C++?

Revision en1, by Giant_on_weed, 2021-12-23 21:23:06

I tried to make a set out of this struct and it gives compilation error

struct triplet{
    int first;
    int second;
    int index;
    bool operator < (const triplet &A){
        if(first==A.first)return second < A.second;
        return first < A.first;
    }
};

The operator works while simple sorting but is giving error while implementing sets, maps and priority_queues.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Giant_on_weed 2021-12-23 21:23:06 500 Initial revision (published)