Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::vector<double> shrink to fit?

Tags:

c++

vector

I'm trying to shrink the size of a vector that I have, but i get an error when i use the myvector.shrink_to_fit(); and it tells me:

error: no member named 'shrink_to_fit' in 'std::vector<double, std::allocator<double> >'

and myvector is defined in the header as:

std::vector<double> myvector;

what does this error mean?

like image 984
Gracita Avatar asked Jan 22 '26 13:01

Gracita


1 Answers

shrink_to_fit is a new C++11 feature that won't be in every compiler yet.

The old way of doing this was to swap with a temporary:

std::vector<double>(myvector).swap(myvector);
like image 103
Mark Ransom Avatar answered Jan 24 '26 06:01

Mark Ransom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!