r/cpp • u/Little-Reflection986 • Feb 16 '26
Favorite optimizations ??
I'd love to hear stories about people's best feats of optimization, or something small you are able to use often!
135
Upvotes
View all comments
Show parent comment
1
u/conundorum Feb 16 '26
Usually, this pattern returns a reference to the passed object, like so:
constcorrectness is used to indicate parameter type:constreference is assumed to be an in-parameter, non-constreference is assumed to be an out-parameter, and by-value is usually assumed to be an elision-friendly "constructed to be moved" in-parameter. (Unless you're working with C-style functions, in which case you just pray.)This does assume that people understand const correctness well enough to instantly grok that the lack of
constmeans the function intends to modify the parameter, so it might be best to document intent with emptyINandOUTmacros, WinAPI style.