I have some (C++14) code that looks like this:
map> junk;
for (int id : GenerateIds()) {
try {
set stuff =
std::map::operator[]
Returns a reference to the value that is mapped to a key equivalent to key, performing an insertion if such key does not already exist.
junk[id]
causes the above mentioned insertion and after that has already happened GetStuff()
throws. Note that in C++14 the order in which these things happen is implementation defined so with a different compiler your junk[id] = GetStuff();
may not do the insertion if GetStuff()
throws.