n.caillou n.caillou - 1 year ago 113
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(); ) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download