#include #include using namespace std; ostream& operator<<(ostream& out, const forward_list& obj); int main() { // Constructors forward_list f1; forward_list f2(5); forward_list f3(5,19); forward_list f4{2,3,5,7,11,13,17}; cout << "f2 = "<< f2 << endl; cout << "f3 = "<< f3 << endl; cout << "f4 = "<< f4 << endl; cout << endl; forward_list f5(f4); forward_list f6(move(f4)); cout << "f4 = "<< f4 << endl; cout << "f5 = "<< f5 << endl; cout << "f6 = "<< f6 << endl; cout << endl; // Capacity functions cout << "f1.max_size() = " << f1.max_size() << ' ' << boolalpha << " f1.empty() = " << f1.empty() << endl << endl; // Access and Iterator functions cout << "f5.front() = " << f5.front() << endl; cout << "*f5.begin() = " << *f5.begin() << endl; cout << "*++f5.before_begin() = " << *++f5.before_begin() << endl << endl; // Modifier functions cout << "assign" << endl; f1.assign(5,7); cout << "f1 = " << f1 << endl; f1.assign({7,6,5,4,3,2,1}); cout << "f1 = " << f1 << endl; cout << endl; cout << "erase_after" << endl; f1.erase_after(f1.begin()); cout << "f1 = " << f1 << endl << endl; cout << "insert_after" << endl; f1.insert_after(f1.before_begin(),3); cout << "f1 = " << f1 << endl; f1.insert_after(f1.begin(),f3.begin(),f3.end()); cout << "f1 = " << f1 << endl << endl; cout << "emplace" << endl; f1.emplace_front(1); cout << "f1 = " << f1 << endl; f1.emplace_after(f1.begin(),2); cout << "f1 = " << f1 << endl << endl; cout << "push_front" << endl; f1.push_front(1); cout << "f1 = " << f1 << endl << endl; cout << "swap" << endl; f1.swap(f6); cout << "f1 = " << f1 << endl; f1.resize(5); cout << "f1 = " << f1 << endl << endl; cout << "reverse" << endl; f1.reverse(); cout << "f1 = "<< f1 << endl << endl; f1.assign({2,4,7,4,5,9,5}); f2.assign({1,5,7,3,6,2,5}); // forward_lists are supposed to be sorted before merge cout << "sort" << endl; cout << "before sort" << endl; cout << "f1 = " << f1 << endl; cout << "f2 = " << f2 << endl; f1.sort(); f2.sort(); cout << "after sort" << endl; cout << "f1 = " << f1 << endl; cout << "f2 = " << f2 << endl << endl; cout << "merge" << endl; cout << "f1.merge(f2);" << endl; f1.merge(f2); cout << "f1 = " << f1 << endl; cout << "f2 = " << f2 << endl << endl; cout << "f1.unique();" << endl; f1.unique(); cout << "f1 = " << f1 << endl << endl; cout << "splice_after" << endl; cout << "f3 = " << f3 << endl; f1.splice_after(++f1.begin(),f3); cout << "f1 = " << f1 << endl; } ostream& operator<<(ostream& out, const forward_list& obj) { for (auto forward_listIt = obj.cbegin(); forward_listIt != obj.cend(); ++forward_listIt) out << *forward_listIt << ' '; return out; }