我的申请合并了两个<代码>std:map例。 如果没有重复,合并就无干预。 然而,如果发现重复,那么这种方法就问,新价值是否应当被忽视或超写。 (可通过向用户发送规则表、电文箱或某种其他逻辑来回答这一问题......这只是一种从一个具有<代码>bool确认() 符合编码>方法的纯虚拟类别衍生的类别的例子。)
If the insert fails, and they decide to overwrite the existing entry, I already have an iterator pointing to the correct item to update. Can I use this iterator to update the value directly, or do I have to call operator[]
and take the hit of another lookup?
// typedef std::map<Foo, Foo, Compare> Dictionary;
// Dictionary this_dictionary, other_dictionary;
for (Dictionary::const_iterator i = other_dictionary.begin();
i != other_dictionary.end();
++i) {
std::pair<Dictionary::iterator,bool> ret = this_dictionary.insert(*i);
if (!ret.second && confirmer.confirm()) {
// ???
}
}