CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

F.16 Is there any reason for cheap-to-copy types (e.g. int, bool, etc.) not be passed as const value?

Open aserebryakov opened this issue 2 years ago • 1 comments

From my experience I prefer the following rule of thumb when writing functions: all input parameters are defined as const or const&.

In my opinion this makes the intent clear and easy to stick to it and also helps to avoid uncontrollable update of the parameter copy inside the function body (the worst case is legacy code with long functions).

Is there any downside to it?

aserebryakov avatar Mar 21 '23 11:03 aserebryakov

there was some discussion of the use of const with function parameters in https://github.com/isocpp/CppCoreGuidelines/issues/1081

cubbimew avatar Mar 21 '23 14:03 cubbimew