C++ vector::clear

后端 未结 6 1075
死守一世寂寞
死守一世寂寞 2020-12-09 09:03
vector  decoy;

void clear_decoy() {  

    decoy.clear();   

    vector (decoy).swap(decoy);  
}

In the above method

6条回答
  •  失恋的感觉
    2020-12-09 09:20

    clear removes all entries from the vector, but may not necessarily deallocate the space. This swap idiom restores the vector to having no space allocated.

提交回复
热议问题