mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
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.
This commit is contained in:
parent
840fa592ac
commit
525d8f225e
|
@ -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`.
|
||||
|
||||
### <a name="Rc-swap-fail"></a>C.84: A `swap` function must not fail
|
||||
|
|
Loading…
Reference in New Issue
Block a user