Is std::vector::reserve(0);
legal and what will it do?
There's nothing to prohibit it. The effect of reserve
is:
After reserve(), capacity() is greater or equal to the argument of reserve if reallocation happens; and equal to the previous value of capacity() otherwise. Reallocation happens at this point if and only if the current capacity is less than the argument of reserve().1
Since the value of capacity()
can never be less than 0 (it's unsigned), this can never have any effect; it can never cause a reallocation.
1. c++ standard, [vector.capacity]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With