Here we are again ... I've implemented my comparsion function:
class Comparator {
public:
bool operator( )(const brCore::brConfigSet& set1, const brCore::brConfigSet& set2) const
{
// check if number of registered config is less
if(set1.getNumberOfConfigs()< set2.getNumberOfConfigs()){
return true;
}
// only check if numbers are equals
else if(set1.getNumberOfConfigs() == set2.getNumberOfConfigs())
{
// check if any given config value is less
for(unsigned int i = 0; i< set1.getNumberOfConfigs(); i++)
{
brCore::brConfig conf1 = set1.getConfig(i);
brCore::brConfig conf2 = set2.getConfig(i);
// first check key values
if(conf1.getKey() < conf2.getKey()){
return true;
}
// finally check config value
if(conf1.asString() < conf2.asString()){
return true;
}
}
}
// return result is equal or grater
return false;
}
};
This comparator checks if the values (each is a string) are less. This works successfully using MSYS
and MinGW, but same code crashes using MSVC 2010 compiler when find operation is performed:
typedef std::map<brCore::brConfigSet, std::string, Comparator> TestMap_t;
TestMap_t map;
brCore::brConfigSet set1("Testset1");
brCore::brConfigSet set2("Testset2");
brCore::brConfig conf1(std::string("value1"), "value1");
brCore::brConfig conf2(std::string("value2"), "value2");
set2.addConfig(conf1.getKey(), conf1);
set2.addConfig(conf2.getKey(), conf2);
map.insert(std::pair<brCore::brConfigSet, std::string>(set1, "hallo"));
map.insert(std::pair<brCore::brConfigSet, std::string>(set2, "buuuu"));
for(TestMap_t::const_iterator p = map.begin( ); p != map.end( ); ++p) {
cout << "Entry: " << " " << p->second << endl;
}
// create test search values
brCore::brConfigSet set3("Testset2");
brCore::brConfig conf31(std::string("value1"), "value1");
brCore::brConfig conf32(std::string("value2"), "value1"); // value change at key results in crash
set3.addConfig(conf31.getKey(), conf31);
set3.addConfig(conf32.getKey(), conf32);
TestMap_t::iterator iter = map.find(set3); // here crash (assert) happends on value change
if(iter!=map.end()){
cout << "Search successfull: " << iter->second << endl;
}
else{
cout << "Search failed for: " << set3.getName() << endl;
}
On MSVC I got an debug assertion as before with an invalid < operator.
The crash occures only if I change the the key of the second config object
to a less value than first A>B , i.e:
brCore::brConfig conf32(std::string("value"), "value1");
But only when I change the key value, if I change the value representation
no crash occurs, i.e.:
brCore::brConfig conf32(std::string("value2"), "value");
I'm running out of ideas why, and why only on MSVC with this
condition