Now that we are talking about STL & templates: What about boost?

On Wed, Jun 2, 2010 at 11:22 AM, Gabriel Dos Reis
<g...@integrable-solutions.net> wrote:
> On Wed, Jun 2, 2010 at 9:05 AM, Paolo Bonzini <bonz...@gnu.org> 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?
>
> yes, it would work, but it may duplicate same executable several times
> for those concerned about code size.
>
> Imagine a vector class template
>
>      template<typename T> struct Vec;    // primary template
>
>      // specialize for T=void*
>      template<>
>         struct Vec<void*> {
>             void* get(int i) { .... }
>             // ...
>         };
>
>      // specialize all T* in terms of void*
>      template<typename T>
>         struct Vec<T*> : private Vec<Void*> {
>            typedef Vec<Void*> Impl;
>            // define all operations in as forwarding functions to Impl
>            T* get(int i) { return static_cast<T*>(Impl::get(i));
>            // and so on.
>         };
>
> you only have one "ultimate" implementation, all others being simple inline
> fowarding functions.  This is for people concerned about code size.
>



-- 
Emilio Wuerges
LAPS - Laboratorio de Automacao de Projeto de Sistemas
UFSC - Universidade Federal de Santa Catarina
Brasil

Reply via email to