From 19992e3284858ec24248ec3c84e4b61bcf3c5230 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Wed, 18 Dec 2024 16:46:30 +0100 Subject: [PATCH] Add move semantics (constructor, operator=) to `List`. --- core/templates/list.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/templates/list.h b/core/templates/list.h index 02afeec74de..14dd0adaede 100644 --- a/core/templates/list.h +++ b/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() {}