std::vector::reserve(0);
合法吗?它会做什么?
最佳答案
没有什么可以禁止的。 reserve
的效果是:
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
因为 capacity()
的值永远不会小于 0(它是无符号的),所以这永远不会有任何效果;它永远不会导致重新分配。
<支持> 1. c++ 标准,[vector.capacity]
关于c++ - 是 std::vector::reserve(0);合法的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26807356/