Skip to content

Commit 947913f

Browse files
committed
use std::map::erase(const_iterator, const_iterator) to get non-constant iterator
1 parent bc94b87 commit 947913f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/limitedmap.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ class limitedmap
6666
}
6767
void update(const_iterator itIn, const mapped_type& v)
6868
{
69-
// TODO: When we switch to C++11, use map.erase(itIn, itIn) to get the non-const iterator.
70-
iterator itTarget = map.find(itIn->first);
69+
// Using map::erase() with empty range instead of map::find() to get a non-const iterator,
70+
// since it is a constant time operation in C++11. For more details, see
71+
// https://stackoverflow.com/questions/765148/how-to-remove-constness-of-const-iterator
72+
iterator itTarget = map.erase(itIn, itIn);
73+
7174
if (itTarget == map.end())
7275
return;
7376
std::pair<rmap_iterator, rmap_iterator> itPair = rmap.equal_range(itTarget->second);

0 commit comments

Comments
 (0)