我很好奇编译器会做多少优化,所以......
// assume we have this declared somewhere
std::vector<int> vec;
// my question is, when fully optimized will this...
for (int i(0); i<100; ++i)
vec.push_back(i);
// evaluate to this? psuedo code...
const size_t size = size();
const size_t newsize = size + 100;
if (size < vec.capacity())
vec.exponentialGrowth();
vec.setSize(newsize);
for (size_t i(size); i<newsize; ++i)
vector[i] = i;
我正在使用启用了优化的 Visual Studio Express 2012。我试过查看反汇编,但优化使其难以阅读。