I need to use lists for my program and needed to decide if I use std::vector or std::list. The problem with vector is that there is no remove method and with list that there is
Given your original problem statement,
I need to use lists for my program and needed to decide if I use std::vector or std::list. The problem with vector is that there is no remove method and with list that there is no operator [].
there is no need to create your own list class (this is not a wise design choice anyway, because std::list
does not have a virtual destructor, which is a strong indication that it is not intended to be used as a base class).
You can still achieve what you want using std::vector
and the std::remove
function. If v
is a std::vector
, then to remove the value value
, you can simply write:
#include
#include
T value = ...; // whatever
v.erase(std::remove(v.begin(), v.end(), value), v.end());