Created
May 31, 2017 16:00
-
-
Save addam/59bd333de9b531a912ca24d148bdc550 to your computer and use it in GitHub Desktop.
pop for c++ map/multimap, works like the Python::dict method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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