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

前端 未结 5 454
一向
一向 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:40

    The std::set allows you to provide your own comparison function, as in

    template < class Key, class Compare = less,
           class Allocator = allocator > class set; 
    

    Only compare the values you care about and it will act as if objects with those values are =. Note that you will probably need a multiset for this.

    This would be the way to do it if you really care about logn performance.

提交回复
热议问题