I have two std::map<> objects a and b and would like to move (extract + insert) some elements (nodes) from one map to the other based on some predicate p.
for (auto i = a.begin(); i != a.end(); ++i)
if (p(*i))
b.insert(a.extract(i))
Run Code Online (Sandbox Code Playgroud)
This code segfaults in clang. I assume the problem is the increment of i after its node has been extracted from a.
Is the right/only way to fix this by using a post-increment?, E.g.:
for …Run Code Online (Sandbox Code Playgroud)