Hi.
given a list and an index i (of type int), how can I erase the i'th element using the STL library?
to be more specific:
I have a class named RadioStation, that holds a list of Playlists as an instance variable:
Code:
list<Playlist> m_playlists;
and I need to implement the following method:
Code:
bool removePlayList(unsigned iPlaylistNumber);
the above method supposed to erase the Playlist whose index is iPlayListNumber.
the naive way to do it (or at least the one that I came up with) is this:
since list::erase takes an iterator to a position, I first set an iterator to the very begining of the list:
Code:
list<Playlist>::iterator iter=m_playlists.begin();
then advancing iter iPlaylistNumber steps ahead:
Code:
std::advance(iter,iPlaylistNumber);
and finally erasing the element:
Code:
m_playlists.erase(iter);
is there other, easier way to do it?
thanks in advanced!