This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using C++ in GCC is OK

On Wed, Jun 2, 2010 at 9:05 AM, 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?

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*
         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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]