#include<iostream> #include<forward_list> using namespace std; int main() { forward_list<int> vi = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto it1 = vi.before_begin(); auto it2 = vi.begin(); while (it2 != vi.end()) { if (*it2 % 2) { it1 = vi.insert_after(it2,*it2); it2++; it2++; } else it2 = vi.erase_after(it1); } for (auto i : vi) cout << i << endl; return 0; }