I have two sets and an iterator to an element of a
:
set<unique_ptr<X>> a, b;
set<unique_ptr<X>>::iterator iter = find something in a;
I would like to remove the element pointed by iter
from a
and insert it into b
. Is it possible? How?
Well, I suspect there is no normal way to do it. But there is always a non-normal one :) You can do the following:
auto tmp = const_cast<std::unique_ptr<std::string>&&>(*iter);
a.erase(iter);
b.insert(std::move(tmp));
Ok, the very first line violated set
invariant and it is horrible but as far as I understand it should not be a problem since on the very next line we remove this evil node from the set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With