taby said:
Thanks again for pointing out the flaw to me. I tried several types of fixes, and the one I settled on was from stackexchange – history_resolution_group* elem = const_cast(&*i); // where i is an iterator
Const-casting is a terrible idea. Don't do it. I can safely say that at your level of experience, there is NEVER a valid reason for using a const-cast (in general there are only limited uses in advanced scenarios).
As I said, the right solution is replacing your set with a map. You are essentially misusing/abusing set here for what its not intended to.
history_resolution_group temp_hrg;
// => remove this parameter from history_resolution_group: temp_hrg.resolution;
// try to insert new hfg
// if exists already, will get iterator to existing, otherwise, will get iterator to new
pair< map<long unsigned int, history_resolution_group>::iterator, bool > pr;
pr = resolutions.insert(temp_params.resolution, temp_hrg);
pr.first->AddFileHRG(src_file_name, temp_params, src_creation_time);
This is just so that you understand it more in your code. You could also simplify it a bit further:
auto pr = resolutions[temp_params.resolution]; // no need to spell out the exact type here
pr.first->AddFileHRG(src_file_name, temp_params, src_creation_time);
Thats why a map is far superior here. []-access will eigther get the element or construct a new one, without you having to manually create a temporary (which is not needed if the element already exists.