Given an iterator into a std::list, how do you replace the object at the position that the iterator references? Currently all I can think of is calling insert with the new object and iterator (to insert the new object before the element referenced by the iterator), and then calling erase to remove the object to be replaced. Is there a less roundabout way of accomplishing a replace?
What's wrong with:
(*it) = obj;
where obj
is the replacement value?
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