Boost logo

Boost :

Subject: Re: [boost] Interesting variadic template trick
From: Jonathan Wakely (jwakely.boost_at_[hidden])
Date: 2013-11-18 06:27:36


On 18 November 2013 10:07, Andrey Semashev wrote:
> On Mon, Nov 18, 2013 at 1:58 PM, Jonathan Wakely
> <jwakely.boost_at_[hidden]> wrote:
>> On 18 November 2013 06:54, Andrey Semashev wrote:
>>>> No it doesn't. It requires exactly two
>>>> instantiations of std::conditional for
>>>> all uses of or_.
>>>
>>> You mean the compiler can optimize multiple instantiations for
>>> different T::value values to just unique ones?
>>
>> How many unique values of bool do you think there are? :-)
>
> I probably didn't express myself clear. I was asking whether the
> compiler is able to optimize N identical instantiations to the cost of
> just one.

There aren't N identical instantiations, there can only be two.

Instantiating a given template specialization is only done once per
translation unit. When it's already instantiated there's nothing to
"optimize", the compiler just refers to the existing instantiation and
uses it, similar to how it would use a non-template class.

Across multiple translation units there might be duplicate
instantiations that can be discarded, but that's dealt with by the
linker, in the same way as duplicate copies of inline functions,
vtables and RTTI info.


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