Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why boost::call_traits<double>::param_type is "const double&", while not "double"

I'm using the code "boost::call_traits::param_type" on a win32 program@windows 7 machine. To my surprise, it's not "double" but "const double&".

I thought all primitive types are good to use "pass by value" for function parameters, isn't that a common sense? Because many people would use is_pod to determine using reference or not, isn't it?

like image 794
JQ. Avatar asked Nov 29 '11 05:11

JQ.


1 Answers

That optimisation apparently only applies to "small" built-in types, according to the doc.

From a quick look at the source, it looks like "small" types are considered as those that satisfy sizeof(T) <= sizeof(void *). On a 32 bit machine this obviously doesn't include double.

In some cases it may well be better to pass parameters as double rather than double const&, but as always, you'd have to benchmark and test...

like image 70
Darren Engwirda Avatar answered Oct 30 '22 10:10

Darren Engwirda