Well most of my code that uses the -- operator for the list::iterator class does so only in cases where it knows it can decrement. For example, I have a game simulator as one of my classes that takes a reference to a list and fills it with the order the players finished from last to first. So when I go to print out the scores, I start at the end and work backwards to print out the top 3 players.
Code:struct GameWinner { string name; double time; ... }; ... GameSimulator sim; list<GameWinner> winners; sim.simulateTournament(winners); list<GameWinner>::iterator cur = winners.end(); winners--; cout << "First place: " << winners->name << " (" << winners->time << ")" << endl; winners--; cout << "Second place: " << winners->name << " (" << winners->time << ")" << endl; ...




Reply With Quote