There's only certain elements I need to access and alter while the rest I want to leave alone.
tl;dr: is there a way to get a list element to return and iterator to the *next* element in the list?
Lists by definition have only sequential access. std::list is doubly linked. If there's a real reason that you can't use a vector...then use iterators. This is just some random stuff you can do.
typedef std::list<int>::iterator IntListIt;
for(IntListIt it = yourlist.start(); it != yourlist.end(); it++)
{
if(NeedsPrevChanged)
{ // Test if prev exists
IntListIt prev = it--;
*prev = *prev - 15;
}
if(NeedsNextChanged)
{ // Test if next exists...
IntListIt next = it++;
*next = *next + 15;
}
if(NeedsNewInsertedBeforeThisElem)
{
yourlist.insert(it, 25);
}
}
If you need the third elem of the list, you'd do the following...which is painfully slow once you get into a list of thousands of elements.
IntListIt ThirdElem = yourlist.start();
for(int i = 1; i < 3; i++)
ThirdElem++;