|
|
|
|
|
by bminor13
2269 days ago
|
|
I have some nitpicks with the advice given in the table: > Q1: Yes Q2: - Q3: No Argument: `Widget& widget` ...or `Widget* widget`, which has drawbacks but makes it more clear at the callsite that the argument passed may be modified. The Google style guide prefers this for this reason: https://google.github.io/styleguide/cppguide.html#Reference_... > Q1: No Q2: No Q3: - Argument: `Widget widget` Q2 IMO should have an addendum to read "Is it expensive to copy a Widget and if not, will it always be cheap" because there is nothing to stop someone from adding to Widget until it crosses the threshold of "expensive", at which point someone needs to go through and update all the callsites to pass by const ref. Widget's copy cost really needs to be part of its API contract before pass-by-value can be allowed. |
|
in ardour, we use the convention that if a null value is allowed, pass a pointer; if a null value is not allowed, pass a ref.
the idea that Widget& implies something different about the likelihood of modification compared with Widget* is quite foreign to me. this is precisely what Widget const & is for.