This is the mail archive of the gcc@gcc.gnu.org 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]

Re: empty function optimizations


Joe Buck wrote:
> 
> > Factoring might be a fair solution for the Linux folks' empty functions.
> > That was Geert's original proposal.  Unfortunately the source of my problem
> > is mostly C++ templates.  I don't have control to factor out the common
> > code.  Well, sure I could have control but then that is like saying "don't
> > use templates".
> 
> No, this is not true.  The technique you need to use is called partial
> specialization.  A typical use is, say, if you have Container<T>, but
> you can use the same code for any case where T is a pointer, or T is
> a PODS (plain old data structure).
> 
> See Chapter 13.5 of Stroustrup's "The C++ Programming Language, 3rd
> Edition" for a good tutorial on how to use this technique.
> 
> Ideally, the STL we provide should use a lot more partial specialization;
> for example
> 

IMHO, that's the wrong approach. It's better to have an optimization in
the compiler than to uglify the code. And the code gets ugly if you do
that. Why should I do what the compiler could do for me?

Regards,
Thomas

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