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

Правка en1, от 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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Giant_on_weed 2021-12-23 21:23:06 500 Initial revision (published)