3 ms·
> And you care about by value vs by reference because copy constructors exist and you need to reason about performance or if you don't need to why are you using
by kllrnohj 7y ago
> And you care about by value vs by reference because copy constructors exist and you need to reason about performance or if you don't need to why are you using c++ anyway?
That's an implementation detail of the function you're calling, not a performance issue at the call site. The call site should not have an opinion on this. Either the object is big enough it should be pass-by-reference, or it's not. You don't need to sprinkle that detail at every call site.
> You mostly care whether it's by value or by reference because what is passed could be altered with the latter unless it's marked const.
For mutable parameters I agree, those should be passed by pointer. Because they actually have an influence at the call site.
But const references, which is what we were talking about, have no behavior change at the call site. So they should not stand out or be marked special, since they aren't.
> But yeah some people are so smart that there is literally nothing in coding readability they need and sneer at those of us who take a different approach.
If you insist all pass-by-const-refs should be pass-by-pointer then you've also lost your ability to code-style distinguish mutable vs. non-mutable parameters. Which makes it much easier to make mistakes, not harder. And also litters your code base with meaningless, non-behavior-altering noise.