Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
How big of a vector are we talking? The FP approach would just copy the vector using copy_if to a new vector. Is it a vector for performance reasons?
-
Iterators aren't really meant for this use case, you want a filter operation or something
-
You should not use a 15 kg hammerhead to make a nail...
An iterator iterates. That's it.
While some languages implement an eg "copy on write" approach to allow modification... It's in my opinion definitely wrong - yes, yadda yadda easy and comfortable, but most approaches (as other people mentioned) will create an copy per modification...
Oops.
There are many alternatives...
Stream -/ Map & Filter
Loop -/ Index & Modify
...
An iterator is a simplified way to allow a generalized, read only access to any data structure - object / array / list, you name it. -
@Root But linked lists are usually a very bad data structure these days because they trash cache locality.
Everybody knows that removing an element from a vector while iterating is a complex task for almost any language -_-' but just try to do it with c++ and get ready to discover that the most robust language is also the one that sucks shit the most
rant