mardi 25 septembre 2018

How does the following one-line comparator work? C++11

I have searched online for a while, but I still cannot figure out how the following one-line comparator works. I know inside the () are the parameters, but where is the return type bool? Is the name of the function omitted? What's the purpose of []?

    /**
     * Definition for an interval.
     * struct Interval {
     *     int start;
     *     int end;
     *     Interval() : start(0), end(0) {}
     *     Interval(int s, int e) : start(s), end(e) {}
     * };
     */
int main(){
    sort(intervals.begin(), intervals.end(), [](Interval& a, Interval& b){return a.start < b.start;});
    return 0;
}

Thanks a lot~

Aucun commentaire:

Enregistrer un commentaire