1
Manjia
4y

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

Comments
  • 0
    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?
  • 4
    Iterators aren't really meant for this use case, you want a filter operation or something
  • 2
    "most robust language" - citation needed
  • 1
    Sounds like an accidental O(n^2) in the making.
  • 2
    linked lists make that absolutely trivial?
  • 3
    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.
  • 0
    i call for @FrodoSwaggins for some input
  • 0
    why the fuck would you do that?
  • 1
    @Root But linked lists are usually a very bad data structure these days because they trash cache locality.
Add Comment