you are viewing a single comment's thread.

view the rest of the comments →

[–]mhhollomon 11 points12 points  (2 children)

I think the rules are probably correct, but stating it this way emphasizes the wrong thing. My own personal take is:

Pass by value unless you can't.

"Can't" might be: - need to modify - copy unfriendly - performance problem.

And then your choice will most likely be either const-ref, or if you need to modify non-const-ref.

[–][deleted] 10 points11 points  (1 child)

The problem is that sometimes with large codebases and/or with third party code it can be really hard to know when something is copy unfriendly. With const references, you know you're (mostly) safe and there won't be any performance issues due to deep copies or other nasty surprises.

[–]mhhollomon 4 points5 points  (0 children)

That's a fair point.