Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a vector before clear?

I'm not sure, but I think I've read that you should only delete a vector if it's not empty. So now I always check before I delete a vector:

if (!vector.empty()) {
    vector.clear();
}

However, I no longer find anything about whether this step is unnecessary.

Is it forbidden to use clear on an empty vector?

like image 401
starcow Avatar asked Jul 26 '26 11:07

starcow


1 Answers

The check is unneeded,

and decrease readability IMO.

like image 162
Jarod42 Avatar answered Jul 28 '26 00:07

Jarod42



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!