From 525d8f225eacf0746332a2a57b1bf1d3ca3050ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20J=2E=20Iglesias=20Garc=C3=ADa?= Date: Thu, 29 Oct 2020 19:12:40 +0100 Subject: [PATCH] Update C.83 with swap for resource mgmt. (#1694) * Update C.83 with swap for resource mgmt. The swap is useful to implement assignments idiomatically (e.g. copy-swap idiom). With the current enforcement, to non-virtual classes, very simple classes (e.g. `trivially_copyable`, a struct encapsulating an stl container) are suggested to have a swap. This suggestion can be argued wrong since for very simple classes copy-swap idiom is not efficient (the creation of a third object on assignment is not needed, which copy-swap does). * Rework C.83 according to PR comments. --- CppCoreGuidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 66409fb..2c22a38 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -6428,7 +6428,7 @@ Providing a non-member `swap` function in the same namespace as your type for ca ##### Enforcement -* (Simple) A class without virtual functions should have a `swap` member function declared. +* Non-trivially copyable value types should provide a member swap or a free swap overload. * (Simple) When a class has a `swap` member function, it should be declared `noexcept`. ### C.84: A `swap` function must not fail -- GitLab