#include #include using namespace std; class countcopy{ public: countcopy(int val = 0) { v = val; } countcopy(const countcopy &cm) { v = cm.v; numcopies++; } #ifdef CPP11 countcopy(countcopy &&cm) noexcept { v= cm.v; nummoves++; } #endif countcopy &operator=(const countcopy &cm) { if (&cm != this) { v = cm.v; numassigns++; } return *this; } #ifdef CPP11 countcopy &operator=(countcopy &&cm) noexcept { if (&cm != this) { // don't need this check, technically v = cm.v; nummassigns++; } return *this; } #endif int v; 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++) { vector > a; for(int j=0;j<100;j++) { vector b; for(int k=0;k<100;k++) b.push_back(countcopy(i+j+k)); #ifdef CPP11 a.push_back(std::move(b)); #else a.push_back(b); #endif } #ifdef CPP11 v.push_back(std::move(a)); #else v.push_back(a); #endif } cout << "# copies: " << countcopy::numcopies << endl; cout << "# assigns: " << countcopy::numassigns<< endl; cout << "# moves: " << countcopy::nummoves << endl; cout << "# move-assigns: " << countcopy::nummassigns<< endl; return 0; }