#include #include using namespace std; class countcopy{ public: countcopy(int val = 0, int val2 = 0) { v = val; v2 = val2;} countcopy(const countcopy &cm) { v = cm.v; numcopies++; } countcopy(countcopy &&cm) noexcept { v= cm.v; nummoves++; } countcopy &operator=(const countcopy &cm) { if (&cm != this) { v = cm.v; numassigns++; } return *this; } countcopy &operator=(countcopy &&cm) noexcept { if (&cm != this) { // don't need this check, technically v = cm.v; nummassigns++; } return *this; } int v,v2; static int numcopies,numassigns,nummoves,nummassigns; }; int countcopy::numcopies = 0; int countcopy::numassigns = 0; int countcopy::nummoves = 0; int countcopy::nummassigns = 0; int main(int argc, char **argv) { vector > >v; for(int i=0;i<100;i++) { v.emplace_back(); // doesn't really save anything for(int j=0;j<100;j++) { v[i].emplace_back(); // doesn't really save anything for(int k=0;k<100;k++) v[i][j].emplace_back(i+j+k,i*j*k); // forwards // arguments (perfectly -- meaning const/volatile // and references are preserved) to constructor // instead of calling default constructor } } cout << "# copies: " << countcopy::numcopies << endl; cout << "# assigns: " << countcopy::numassigns<< endl; cout << "# moves: " << countcopy::nummoves << endl; cout << "# move-assigns: " << countcopy::nummassigns<< endl; return 0; }