当前位置: 代码迷 >> 综合 >> Effective STL 17 Use the swap trick to trim excess capacity
  详细解决方案

Effective STL 17 Use the swap trick to trim excess capacity

热度:23   发布时间:2024-01-03 09:30:39.0

for vector

vector<int>(v.begin(), v.end()).swap(v);

for string

string(s.begin(), s.end()).swap(s);

both to clear a container and to reduce its capacity to the minmum your implementation offers.

vector<int>().swap(v);
string().swap(s);
  相关解决方案