What are the benefits to passing integral types by const ref

前端 未结 12 1827
情话喂你
情话喂你 2021-02-05 22:18

The question: Is there benefit to passing an integral type by const reference as opposed to simply by value.

ie.

void foo(const int& n); // case #1
<         


        
12条回答
  •  清歌不尽
    2021-02-05 22:56

    You can use boost::call_traits::param_type for optimal parameter passing. Which defaults to simple parameter passing of primitive types and passing by const reference of structs and classes.

提交回复
热议问题