From 802e928737ea4260f60f0a163091b2f4b5f47f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Tue, 27 Sep 2016 19:23:09 +0200 Subject: [PATCH] Updated NEP 2 Catching up with C and Rust: Ownership, destructors, unique pointers (markdown) --- ...---and-Rust:-Ownership,-destructors,-unique-pointers.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md b/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md index 22f6fa6..dc7ddbc 100644 --- a/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md +++ b/NEP-2-Catching-up-with-C---and-Rust:-Ownership,-destructors,-unique-pointers.md @@ -50,5 +50,12 @@ proc `=`(dst: var MyType; src: MyType) = dst.resources = src ``` +I just heard, that self assignment on types that have deinitialization would not work anymore. This can be handled by implementing some logic that checks weather it is selft assignment, or by simply declaring self assignment illegal. One version that works with self assignment is the following (again in psoudocode), but it still needs to explain what move semantics are. +```Nim +proc `=`(dst: var MyType; src: MyType) = + tmp <- copy(src) + destroy(dst) + dst <- tmp +```