Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-07-06 12:07:37

On Jul 6, 2004, at 11:37 AM, David B. Held wrote:

> "Howard Hinnant" <hinnant_at_[hidden]> wrote in message
>> [...]
>> I initially viewed call_traits as a way to optimize whether a type
>> should be passed by const ref or by value. But I was mistaken.
>> The real value was in passing/returning reference types without
>> bumping into the reference-to-reference problem.
> So are you saying that call_traits is *not* useful for said
> optimization? If so, why not?

For it to make a significant difference in performance, say for passing
a parameter, the function would have to be very short - short enough
that it should be inlined.

On Metrowerks Pro 9.2 / Mac I've just run the following experiment:

int foo1(int i)
        return i;

int foo2(const int& i)
        return i;

int main()
        int i = 1;
        return foo1(i);

I've looked at the generated (optimized) assembly of main, using both
foo1 and foo2. The assembly is identical in both cases. No doubt I
could come up with examples where the assembly is different. But I'm
having more trouble coming up with a situation where the performance
difference is enough that I'd want to start lacing my generic code with
call_traits for this purpose. However if you have such examples, I'm
interested in pursuing this further.


Boost list run by bdawes at, gregod at, cpdaniel at, john at