sortuj std :: set używając operatora (), aby zamówić wstawienia
Kontynuuję ten post poTo mamy klasę jako:
class LaneConnector {
public:
const Lane* getLaneFrom() const {
return From;
}
const Lane* getLaneTo() const {
return To;
}
private:
Lane* From;
Lane* To;
}
i functor do porównania jako:
struct MyLaneConectorSorter {
bool operator() (const LaneConnector* rhs, const LaneConnector* lhs) const
{
// you may want to put some null pointer checks in here
const Lane* a = lhs->getLaneFrom();
const Lane* b = rhs->getLaneFrom();
return a->getLaneID() < b->getLaneID();
}
};
i wreszcie zestaw źródłowy i docelowy:
const std::set<LaneConnector*> src = ..... ;
const std::set<LaneConnector*, MyLaneConectorSorter> dest(src.begin(), src.end(), MyLaneConectorSorter());
Rozmiar zestawu dest wynosi 1, podczas gdy src ma więcej (14 w moim przypadku)
co mogłem zrobić źle? Cenię twoje miłe komentarze. Dziękuję Ci