- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
48 lines
961 B
Markdown
48 lines
961 B
Markdown
# Array::Size() / Capacity() / Empty()
|
||
|
||
```cpp
|
||
size_t Size() const;
|
||
size_t Capacity() const;
|
||
bool Empty() const;
|
||
```
|
||
|
||
获取数组的尺寸信息。
|
||
|
||
**Size():** 返回数组中的实际元素数量。
|
||
|
||
**Capacity():** 返回底层内存缓冲区能容纳的元素数量,不一定等于 `Size()`。
|
||
|
||
**Empty():** 返回数组是否为空(`Size() == 0`)。等价于 `Size() == 0`,但更语义化。
|
||
|
||
**返回:**
|
||
- `Size()` - 元素数量
|
||
- `Capacity()` - 底层缓冲区容量
|
||
- `Empty()` - 是否为空
|
||
|
||
**复杂度:** O(1)
|
||
|
||
**示例:**
|
||
|
||
```cpp
|
||
Containers::Array<int> arr;
|
||
|
||
arr.Size(); // 0
|
||
arr.Capacity(); // 0
|
||
arr.Empty(); // true
|
||
|
||
arr.PushBack(1);
|
||
arr.PushBack(2);
|
||
|
||
arr.Size(); // 2
|
||
arr.Capacity(); // 4(自动扩容)
|
||
arr.Empty(); // false
|
||
|
||
arr.Reserve(100);
|
||
arr.Size(); // 2(元素数量不变)
|
||
arr.Capacity(); // 100(容量增加)
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Array 总览](array.md) - 返回类总览
|