Lived once

struct Point { double lat; double lon; time_t when; }; 

which were stored in std::list (data is initially sorted by when ). It took an exception of duplicates in lat / lon , for which the list was converted to std :: set

 bool operator < (const Point &point) const { return (this->lat < point.lat || this->lon < point.lon) && this->when < point.when; } 

Everything is good, but it is necessary that subsequent duplicates are not deleted, but old ones are overwritten.

  • The first thought is to use map , and rewrite in the spirit of m[x] = x ... Formally speaking, you don’t have a lot of it, but a display of the lat/lon key on the when value. Another option - search, delete and insert a new one? - Harry
  • I changed the title - there can be no duplicates in std::set . - ixSci
  • @ixSci so the reason for changing the question is more correct, IMHO, in the corresponding description field to add when editing, and not to make comments :) - αλεχολυτ
  • @alexolut, yeah, I just never use it. I'll have to get used to it - ixSci

1 answer 1

If you need to restrict existing values ​​in the set, then before adding ( insert ) to std::set you need to check for the presence of such an element through std::set::find . If the item is found, delete the existing one and then add a new one.