Skip to content

Instantly share code, notes, and snippets.

@addam
Created May 31, 2017 16:00
Show Gist options
  • Save addam/59bd333de9b531a912ca24d148bdc550 to your computer and use it in GitHub Desktop.
Save addam/59bd333de9b531a912ca24d148bdc550 to your computer and use it in GitHub Desktop.
pop for c++ map/multimap, works like the Python::dict method
template<typename M>
M::mapped_type pop(M &m, M::const_iterator it)
{
assert (it != m.end());
M::mapped_type result = *it;
m.erase(it);
return result;
}
template<typename M>
M::mapped_type pop(M &m)
{
return pop(m, m.begin());
}
template<typename M>
M::mapped_type pop(M &m, const M::key_type &k)
{
return pop(m, m.find(k));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment