35 lines
862 B
Markdown
35 lines
862 B
Markdown
|
|
# HashMap::Copy/Move 构造
|
|||
|
|
|
|||
|
|
```cpp
|
|||
|
|
HashMap(const HashMap& other);
|
|||
|
|
HashMap(HashMap&& other) noexcept;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
拷贝构造和移动构造。
|
|||
|
|
|
|||
|
|
**参数:**
|
|||
|
|
- `other` - 源哈希表(拷贝版本为 `const` 引用,移动版本为右值引用)
|
|||
|
|
|
|||
|
|
**返回:** 无(构造函数)
|
|||
|
|
|
|||
|
|
**复杂度:**
|
|||
|
|
- 拷贝构造:O(m_bucketCount + other.m_size)
|
|||
|
|
- 移动构造:O(1),直接接管源对象的内部资源
|
|||
|
|
|
|||
|
|
**示例:**
|
|||
|
|
|
|||
|
|
```cpp
|
|||
|
|
XCEngine::Containers::HashMap<int, std::string> map1;
|
|||
|
|
map1.Insert(1, "hello");
|
|||
|
|
map1.Insert(2, "world");
|
|||
|
|
|
|||
|
|
XCEngine::Containers::HashMap<int, std::string> map2(map1); // 拷贝构造
|
|||
|
|
|
|||
|
|
XCEngine::Containers::HashMap<int, std::string> map3(std::move(map1)); // 移动构造,map1 在此调用后状态不确定
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 相关文档
|
|||
|
|
|
|||
|
|
- [HashMap 总览](hashmap.md) - 返回类总览
|
|||
|
|
- [operator=](operator-assign.md) - 赋值运算符
|