Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing std::list object given an iterator

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?

like image 414
dbotha Avatar asked Jul 26 '11 21:07

dbotha


1 Answers

What's wrong with:

(*it) = obj;

where obj is the replacement value?

like image 78
Oliver Charlesworth Avatar answered Sep 30 '22 19:09

Oliver Charlesworth