n.caillou n.caillou - 11 months ago 96
C++ Question

c++11, salvaging a set

Is there a clean way of moving the elements of a set out of it ? Something like:

set<A> s {...};
vector<A> v;
for (const A& a : s)
s.clean(); //undefined behavior?

Answer Source

In C++11, no. The move you're doing is undefined behavior.

In C++17, yes, with extract():

for (auto it = s.begin(); it != s.end(); ) {