-
Recent Posts
Recent Comments
Archives
Categories
Category Archives: STL
Avoid finding twice the same key in the map (part 2)
Later, I found the following code:
1 2 3 4 5 6 |
auto p = map.find(key); if (p != map.end()) { throw std::runtime_error(...); } prepare(value); map[key] = value; |
Posted in C++, C++11, STL
Leave a comment
Avoid finding twice the same key in the map (part 1)
This is unfortunate, but I regularly still see the following piece of code:
1 2 3 4 5 |
auto p = map.find(key); // (1) if (p != map.end()) { throw std::runtime_error(...); } map[key] = value; // (2) |
Posted in C++, C++11, STL
Leave a comment