问个C++ 11新特性的有关问题,疑惑
问个C++ 11新特性的问题,疑惑
看到一个stl hash table的源码实现中,一个成员函数为何提供2个版本,只是形参不一样,实现完全不一样。
既然有了const hash_map&m 为何要有hash_map&& m呢?不解。
------解决方案--------------------
自己google 右值引用
看到一个stl hash table的源码实现中,一个成员函数为何提供2个版本,只是形参不一样,实现完全不一样。
既然有了const hash_map&m 为何要有hash_map&& m呢?不解。
258 void copy_from(hash_map&& m)
259 {
260 if(m.empty()) return;
261 for(size_t idx = 0; idx < m.capacity_; ++idx)
262 {
263 if(is_key_deleted(m.buckets_[idx].first) ||
264 is_key_empty(m.buckets_[idx].first))
265 continue;
266 _insert(std::move(m.buckets_[idx]));
267 }
268 }
269 void copy_from(const hash_map& m)
270 {
271 if(m.empty()) return;
272 for(size_t idx = 0; idx < m.capacity_; ++idx)
273 {
274 if(is_key_deleted(m.buckets_[idx].first) ||
275 is_key_empty(m.buckets_[idx].first))
276 continue;
277 _insert(m.buckets_[idx]);
278 }
279 }
------解决方案--------------------
自己google 右值引用