浏览代码

Add move semantics (constructor, operator=) to `List`.

Lukas Tenbrink 8 月之前
父节点
当前提交
19992e3284
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13 0
      core/templates/list.h

+ 13 - 0
core/templates/list.h

@@ -522,6 +522,15 @@ public:
 			it = it->next();
 		}
 	}
+	void operator=(List &&p_list) {
+		if (unlikely(this == &p_list)) {
+			return;
+		}
+
+		clear();
+		_data = p_list._data;
+		p_list._data = nullptr;
+	}
 
 	// Random access to elements, use with care,
 	// do not use for iteration.
@@ -760,6 +769,10 @@ public:
 			it = it->next();
 		}
 	}
+	List(List &&p_list) {
+		_data = p_list._data;
+		p_list._data = nullptr;
+	}
 
 	List() {}