Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2008-07-01 16:49:41


Eric Niebler wrote:
> David Abrahams wrote:
>> Eric Niebler wrote:
>>> David Abrahams wrote:
>>>> Eric Niebler wrote:
>>>>> David Abrahams wrote:
>>>>>> Eric Niebler wrote:
>>>>>>
>>>>>> -- snip 2^10 overloads --
>>>>>>
>>>>>> Yeah, that's probably too much, but I'm not sure we have to support
>>>>>> forwarding for that many arguments. The only thing rvalue forwarding
>>>>>> buys you (and it can be a big win) is the ability for the wrapped
>>>>>> thing
>>>>>> to make certain optimizations. It's a good idea when you can do
>>>>>> it. If
>>>>>> you can't do it, you can fall back to lvalues and in C++03 you've
>>>>>> still
>>>>>> done a credible job.
>>>>> Even 2^3 overloads has a *very* noticeable effect on compile times.
>>>> 8 overloads hurts compile times?
>>> Yes, because for each function invocation you have to calculate the
>>> return type 8x in 8 different ways.
>>
>> Hmm. Why? Seems to me that only one specialization of the wrapped
>> class template needs to be instantiated per invocation.
>
>
> Take the simple case with 1 arg:
>
> template<typename T>
> typename result_of<F(T &)>::type
> fun( T & t );
>
> template<typename T>
> typename result_of<F(T const &)>::type
> fun( T const & t );
>
> Now I invoke fun(x). The compiler has to do overload resolution. First
> it has to determine function signatures. In so doing, it computes the
> return type for both overloads. For 3 arguments there are 8 overloads
> and the return type needs to be calculated 8x in 8 different ways, even
> though only one will ever be used.

Oh, sure. Technically compilers should be able to defer computing the
return type until after the rest of the signature wins overload
resolution, but that's not the way they work today. I *think* we're
getting that for 0x, though.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk