Skip to content

Instantly share code, notes, and snippets.

@psycharo-zz
Last active December 18, 2015 04:49
Show Gist options
  • Save psycharo-zz/5728665 to your computer and use it in GitHub Desktop.
Save psycharo-zz/5728665 to your computer and use it in GitHub Desktop.
insert and replace in the map if an entry already exists
/**
* insert and replace if an entry already exists
*/
template <class TKey, class TVal>
void map_insert(std::map<TKey, TVal> &values, const std::pair<TKey, TVal> &val)
{
std::pair<typename std::map<TKey,TVal>::iterator, bool> res = values.insert(val);
if (!res.second)
res.first->second = val.second;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment