turning IntArray into a class template
IntArray to Vectemplate <typename T>push_back() takes const T& nowoperator<<() to a function templateVec<int> and Vec<string>Value semantics of STL containers
Stack & heap diagram for the following sequence of code:
Vec<MyString> v;
v.push_back("abc");
v.push_back("def");
MyString s{"xyz"};
v.push_back(s);
Vec<MyString> holds MyString objects by value
There is no copy construction of MyString objects
push_back() invokes MyString::operator=()Placement new
std::vector does not default-construct elements on empty slotsvector::push_back() construct an object at existing memory?Placement new syntax:
new (p) MyString{"xyz"};
Strong Exception Guarantee
IntArray -> Vec changesstd::vector move vs. copy