3 ms·
No copying here: struct person { int age; }; std::list<person> people; people.push_back(person()); people.back().age = 42;
by 430gj9j 14y ago
No copying here:
struct person { int age; };
std::list<person> people;
people.push_back(person());
people.back().age = 42;
- archangel_one 14y agoIt copies on the third line prior to C++0x, and unfortunately not everyone can rely on move semantics yet.
- mpyne 14y agoActually in this particular case that "copy" is allowed to be elided even in C++98, as the copy constructor of person produces no side effects. It would be hard to notice if the optimizer is that smart or not either way though, since it will be optimized by redundant load/store elimination even if it was initially generated without optimization.
- malkia 14y agoAnd that's the other reason of not using C++ sometimes - you just don't know exactly what happens.