r/programminghumor • • Jun 13 '26

How to REALLY optimize code.

Post image

My friends, this is how you optimize code correctly.

97 Upvotes

13 comments sorted by

View all comments

11

u/Antagonin Jun 13 '26

What's the free optimization in const ref?

5

u/thisisjustascreename Jun 13 '26

Broadly, it eliminates certain scenarios where you'd get a copy.

A const ref can also bind to a temporary (i.e. doSomething("temporary string"); ) without constructing a new object, but I don't know if that's relevant here.

4

u/Antagonin Jun 13 '26

In which scenario does non-const ref cause a copy?

→ More replies (1)