У меня проблема с использованием
Код: Выделить всё
lower_boundI have a
Код: Выделить всё
struct person{
public:
person(const std::string CITY, const std::string ADDRESS, const std::string REGION, const unsigned ID, std::string PARENT = ""): m_city(CITY), m_addr(ADDRESS), m_region(REGION), m_id(ID), m_parent(PARENT) {}
std::string m_city;
std::string m_addr;
std::string m_region;
unsigned m_id;
std::string m_parent;
};
Код: Выделить всё
std::vectorКод: Выделить всё
lower_boundКод: Выделить всё
vectorMy approach works the worst way. Most of the time it doesn't find anything.
Код: Выделить всё
auto iteratorRegion = findPerson(m_sortedByRegion, candidatePerson);
std::vector::iterator findPerson(std::vector& ARRAY, const person& candidatePerson) const {
auto iterator = std::lower_bound(ARRAY.begin(), ARRAY.end(), candidatePerson, cityAdressComparator); if (iterator != ARRAY.end() && iterator->m_city == candidatePerson.m_city && iterator->m_addr == candidatePerson.m_addr) {
return iterator;
}
auto iterator2 = std::lower_bound(ARRAY.begin(), ARRAY.end(), candidatePerson, regionIDComparator); if (iterator2 != ARRAY.end() && iterator2->m_region == candidatePerson.m_region && iterator2->m_id == candidatePerson.m_id) {
return iterator2;
}
return ARRAY.end();
}
Код: Выделить всё
if (!(realEstateL.m_city == realEstateR.m_city))
{
return realEstateL.m_city < realEstateR.m_city;
}
return realEstateL.m_addr < realEstateR.m_addr;
Источник: https://stackoverflow.com/questions/781 ... parameters
Мобильная версия