Rule of thumb for when passing by value is faster than passing by const reference?

前端 未结 7 1791

Suppose I have a function that takes an argument of type T. It does not mutate it, so I have the choice of passing it by const reference const T&

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 16:24

    If you're going to use a "rule of thumb" for by-value vs. by-const-reference, then do this:

    • pick ONE approach and use it everywhere
    • agree upon which one among all your coworkers
    • only later, in the "hand-tuning performance" phase, start changing things
    • and then, only change them if you see a measurable improvement

提交回复
热议问题