Re:Mistakes to avoid with C++ 11 smart pointers
by sytelus on Saturday May 14, 2016 @11:57PM
(#11699356)
I generally prefer to pass by const ref. If function needs to make copy, it can always invoke copy constructor. If it doesn't then all is well and performant. I know there are optimizations that can happen if you pass by value and function intends to make a copy. But those are micro optimizations and I've always felt its not worth the confusion it creates to the caller as well as callee. Does anyone else follow this general rule of thumb?
[ Parent
| on HN ]
Re:Mistakes to avoid with C++ 11 smart pointers
by maxlybbert on Sunday May 15, 2016 @11:02AM
(#11701149)
I used to do the same thing, until I saw slides ( https://stlab.adobe.com/wiki/images/8/85/2008_06_26_classes_... ) for a talk ( https://my.adobeconnect.com/p53888531/?launcher=false&fcsCon... ) that pointed out that explicitly making the copy makes it much harder for the compiler to do copy elision.