$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: John Moeller (fishcorn_at_[hidden])
Date: 2008-05-19 11:50:42
Hervé Brönnimann <hervebronnimann <at> mac.com> writes:
> On May 15, 2008, at 10:40 AM, John Moeller wrote:
> > Fair enough.  I think, though, if you're going to try to make sure  
> > that
> > the compiler doesn't miss multiplication by 1, you may as well go  
> > all the
> > way and add another template parameter to capture N%2, and get rid  
> > of the
> > ternary statement:
> 
> To be clear, I'm not concerned about optimizing multiplication by 1  
> for builtin types, of course.  But it seems to me that the compiler  
> shouldn't really be able to optimize for user-defined types (what if  
> multiplication isn't inlined, for instance...)
And regardless of whether the type is builtin or not, branching with template 
parameters will accomplish the same task as letting the compiler decide to 
inline a ternary statement, except that it will be explicit.  There is zero 
chance of the compiler generating more instructions than are needed (unless 
inlining breaks down).  I know that this ternary statement's condition may be 
evaluated at compile time, so there is little chance of more than one branch 
being generated, but why not just make it explicit?
(From an aesthetic standpoint, I think branching with a template parameter 
expresses the recursion very elegantly (two branches, one base condition), and 
doesn't get in the way at all.  Elegance isn't really what matters here, 
though.)
My response wasn't motivated emotionally; I agree with your argument about UDT 
multiplication (as I did when I wrote my response in the first place).  I'm 
just saying it would be advantageous to follow the process further.  
-- John Moeller