Boost logo

Boost :

Subject: Re: [boost] [review] Review of PolyCollection starts today (May 3rd)
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2017-05-16 17:41:42

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<typename Model,typename Allocator>
>> bool operator==(
>> const poly_collection<Model,Allocator>& x,
>> const poly_collection<Model,Allocator>& y)
>> {
>> typename poly_collection<Model,Allocator>::size_type s=0;
>> const auto &,&;
>> 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<typename Model,typename Allocator>
   bool operator==(
     const poly_collection<Model,Allocator>& x,
     const poly_collection<Model,Allocator>& y)
     typename poly_collection<Model,Allocator>::size_type s=0;
     const auto &,&;
     for(const auto& p:mapx){
       auto it=mapy.find(p.first);
if(it==mapy.end()?!p.second.empty():p.second!=it->second)return false;
     if(s!=y.size())return false;
     return true;

> 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

Boost list run by bdawes at, gregod at, cpdaniel at, john at