El 16/05/2017 a las 16:20, Thorsten Ottosen via Boost escribió:
Den 15-05-2017 kl. 21:21 skrev Joaquin M López Muñoz via Boost:
I think this variation of a) might perform better (code untested):
template
bool operator==( const poly_collection & x, const poly_collection & y) { typename poly_collection ::size_type s=0; const auto &mapx=x.map,&mapy=y.map; for(const auto& p:mapx){ s+=p.second.size(); auto it=mapy.find(p.first); if(it==mapy.end()?!p.second.empty():p.second!=it->second)return false; } if(s!=mapy.size())return false; return true; } I not sure about this version. mapy.size() should be y.size() ?!?
My typo, it should read as you say:
template
Or do you need sx and sy? But also, once all the segments have been compared in the loop, you know the x.size() == y.size() ...
Not so: consider the case where y has a segment (let's call it seg) which is not present in x; in this case the for loop would pass succesfully and seg wouldn't have been hit, and we'd thus erroneously return true. That's why we need the extra check on size. In other words, we can't determine equality by only going through x's segments. Joaquín M López Muñoz