On 2 June 2010 15:05, Paolo Bonzini wrote:
> On 06/02/2010 03:01 PM, Gabriel Dos Reis wrote:
>>
>> In the guidelines, I would like to include:
>>    (2) if you define a class template used mostly with pointer type
>> arguments,
>>         consider specializing for void* (or const void*) and define all
>> other
>>         pointer specialization in terms of that.
>
> I have no idea what you're saying. :-)  What do you mean by "define all
> other pointer specialization in terms of that"?  Wouldn't specializing on T*
> just work?

It would work, but can result in a large number of instantiations
which generate identical instructions.  This sort of "template bloat"
is possible with C++, but is easily avoided.

I think what Gaby proposes is to have a common implementation in terms
of void*, and then specialisations for other pointer types which are
simple forwarding wrappers around the void* specialisation with
appropriate casts.  This can greatly reduce the amount of code
generated if you use the function with many pointer types, because the
bulk of the code is only instantiated once for void*.

Reply via email to