How to find an object with specific field values in a std::set?

前端 未结 5 426
一向
一向 2020-12-03 16:09

I call a method which returns std::set const& where T is a class type. What I\'m trying to achieve is to check whether the set contain

5条回答
  •  粉色の甜心
    2020-12-03 16:29

    You may try overriding operator<(const T& a, const T& b) to impose an order on those attributes, so std::set:find(const T& x) will return the first no less than x.

    Ej:

    bool operator<(const Car& a, const Car& b)
    {
        return a.color cars;
    Car x;
    cars.find(x);
    

提交回复
热议问题