#include #include using namespace std; ostream& operator<<(ostream& out, const vector& v); int main() { // Constructors vector v1; vector v2(5); vector v3(5,19); vector v4{2,3,5,7,11,13,17}; cout << "v2=" << v2 << endl; cout << "v3=" << v3 << endl; cout << "v4=" << v4 << endl << endl; vector v5(v4.begin(),v4.begin()+3); vector v6(v4); vector v7(move(v4)); cout << "v4=" << v4 << endl; cout << "v5=" << v5 << endl; cout << "v6=" << v6 << endl; cout << "v7=" << v7 << endl << endl; // Capacity functions cout << "v7.size()=" << v7.size() << endl; cout << "v7.capacity()=" << v7.capacity() << endl; cout << "v7.max_size()=" << v7.max_size() << endl; v7.reserve(16); v7.resize(v7.size()*2); cout << "v7.size()=" << v7.size() << endl; cout << "v7.capacity()=" << v7.capacity() << endl; cout << "v7=" << v7 << endl; v7.shrink_to_fit(); cout << "v7.size()=" << v7.size() << endl; cout << "v7.capacity()=" << v7.capacity() << endl << endl; // Access functions cout << "v6.front()=" << v6.front() << endl; cout << "v6.back()=" << v6.back() << endl; cout << "v6.at(3)=" << v6.at(3) << endl; int* ptr = v6.data(); cout << *ptr << ' ' << *(ptr+2) << endl; for (auto* p = v6.data(); p < v6.data()+v6.size(); ++p) *p *= 2; cout << "v6=" << v6 << endl << endl; // Modifier functions v1.assign({7,6,5,4,3,2,1}); cout << "v1=" << v1 << endl; v2.assign(v1.crbegin(),v1.crend()); cout << "v2=" << v2 << endl; v2.erase(v2.begin()+3); cout << "v2=" << v2 << endl; v2.insert(v2.begin()+3,15); v2.pop_back(); v2.push_back(30); cout << "v2=" << v2 << endl; v1.swap(v2); cout << "v1=" << v1 << endl; cout << "v2=" << v2 << endl << endl; // Member operators v1[2] = v2[3]*2; cout << "v1=" << v1 << endl; v1.assign(v2.begin(),v2.begin()+5); v1.push_back(13); cout << "v1=" << v1 << endl; cout << "v2=" << v2 << endl << endl; v3 = v1; v3.resize(10); cout << "v3=" << v3 << endl; cout << boolalpha; cout << "v1 == v3: " << (v1 == v3) << endl; cout << "v1 < v2: " << (v1 < v2) << endl; cout << "v1 < v3: " << (v1 < v3) << endl; cout << "v2 < v3: " << (v2 < v3) << endl; } ostream& operator<<(ostream& out, const vector& v) { for (auto element : v) out << element << ' '; return out; }