CppCoreGuidelines
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?
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?
there was some discussion of the use of const with function parameters in https://github.com/isocpp/CppCoreGuidelines/issues/1081