[REDMINE1D-25] [RM-6371] [wiki] Check and Apply "Rule of zero" or else "Rule of the 5 defaults", to possibly all classes in the library Created: 04/Jun/21  Updated: 09/Dec/23  Resolved: 09/Dec/23

Status: Done
Project: 1D Redmine
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Normal
Reporter: Redmine-Jira Migtation Assignee: Redmine-Jira Migtation
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Image collée à 2021-12-1 16-10.png    

 Description   

Created on 2021-03-15 13:11:55 by Mira Sarkis. % Done: 100

Motivations for this action (based on https://www.fluentcpp.com/2019/04/23/the-rule-of-zero-zero-constructor-zero-calorie/):
Among the new practices in C++11 appears the Rule of 5 vs Rule of zero

  • "Rule of 5" states that if any of the "Big Five" (i.e., the copy/move constructors, copy/move assignment operators or destructor) has a user-defined implementation, we should obligatory define the implementation of the remaining "Big Fives" .
    This is important because otherwise we will have to deal with some side effects notably on the generation of the move operations. In most of the cases move operations are replaced by copy operations (which are far more expensive than the former).
    This applies also when setting to 'default' at least one of the "Big Fives" and the rest non-default
  • "Rule of 5 default ", always declare the 5 resource-management functions. And if they are trivial, use @= default@. This avoid, for instance, the non implicit generation of the 2 move functions, without the need to explicit their definitions.
  • "Rule of zero": do not define any of the "Big Five".

Conclusion and rules to check their correct usage in the library:

  • stick to rule of zero if there is no need for user-defined implementation
  • if one of the Big Five should be user-defined, then explicitly default the rest


 Comments   
Comment by Redmine-Jira Migtation [ 09/Dec/23 ]

Comment by Didier Vibert on 2022-01-14 08:41:04:

Comment by Redmine-Jira Migtation [ 09/Dec/23 ]

Comment by Pierre-yves Chabaud on 2022-03-15 13:46:11:
Create a related wiki page

Comment by Redmine-Jira Migtation [ 09/Dec/23 ]

Comment by Didier Vibert on 2023-12-08 09:56:11:
https://projets.lam.fr/projects/amazed/wiki/AmazedDeveloperGuide#Good-practices-for-cpp

Generated at Sat Feb 10 15:28:32 JST 2024 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.