I’ve been trying to use extract()
to efficiently pull out a key and replace it, as the documentation says is possible. However, I can’t get my code to compile with a “regular” iterator
, and the documentation implies that a const_iterator
must be used instead.
Here’s the code I’ve been using:
auto nodehandler = m_map.extract(replace_iter);
nodehandler.key = keyBegin;
nodehandler.value = val;
m_map.insert(replace_iter,nodehandler);
I’ve looked into const_iterator
a little bit, and it seems like the purpose behind it is that it can only access containers, but not modify them, but the documentation seems pretty strong on only using const_iterator
in extract()
, which is explicitly for modifying the std::map container, so I really don’t understand that.
Furthermore, I’m not sure how to actually get a const_iterator
to begin with, or use one. I tried casting my iterator
to be of type const_iterator
, but I don’t think that was ever going to work.
const_iterator test_iter = (const_iterator)replace_iter;
/*auto nodehandler = m_map.extract(test_iter);
nodehandler.key = keyBegin;
... etc.
*/
So what’s the right way to actually get this to work?
1