sort std::set using operator() to order the insertions

前端 未结 2 1999
清酒与你
清酒与你 2021-01-29 04:31

I am continuing this post after This we have a class as:

class LaneConnector {
public:

    const Lane* getLaneFrom() const {
        return From;
    }
    con         


        
相关标签:
2条回答
  • 2021-01-29 04:44

    There is a very simple way to catch problems like this way before they get a chance to expose themselves. Write unit tests!

    My guess is that all your LaneConnectors start at the same line. So, GetLaneFrom()->GetLaneID() yields the same result on all LaneConnectors

    0 讨论(0)
  • 2021-01-29 04:53

    std::set keeps track of elements based on the key. In your comparator you have return a->getLaneID() < b->getLaneID();. Thus Lane ID implicitly becomes the key. Since if a and b have the same LaneID, then both MyLaneConectorSorter(a, b) and MyLaneConectorSorter(b, a) are returning false.

    Your set thus can not contain more than one LaneConnectior with the same LaneID.

    0 讨论(0)
提交回复
热议问题