samedi 23 mai 2020

I wonder that if the temporary object(name_compare()) is passed by value or by reference to std::sort

I wonder that if the temporary object(name_compare()) is passed by value or by reference to std::sort.

I would be thankful for any hint on this question.

 struct Record {
        string name;
        // ...
    };
    struct name_compare {   // compare Records using "name" as the key
        bool operator()(const Record& a, const Record& b) const
            { return a.name<b.name; }
    };
    void f(vector<Record>& vs)
    {
        sort(vs.begin(), vs.end(), name_compare());
        // ...
    }  

Aucun commentaire:

Enregistrer un commentaire