mardi 25 mai 2021

What does bool operator() do?

I am not able to understand this piece of code from GeeksforGeeks:

// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
  
// Comparison function for sorting the
// set by increasing order of its pair's
// second value
struct comp {
    template <typename T>
  
    // Comparator function
    bool operator()(const T& l,
                    const T& r) const
    {
        if (l.second != r.second) {
            return l.second < r.second;
        }
        return l.first < r.first;
    }
};

I find similar article in StackOverflow. but all of them are little different.

I also want to ask, what is the difference between writing bool operator () and operator bool()?

Aucun commentaire:

Enregistrer un commentaire