On 1/22/07, Sami <randomaccessiterator@gmail.com> wrote:
Hi Tony,
 
Thx for your reply first of all.  
 
On 1/22/07, Gottlob Frege < gottlobfrege@gmail.com> wrote:


On 1/22/07, Sami < randomaccessiterator@gmail.com > wrote:
Hi All,

 
    if (Pow == 0) return 1; // to do argue about the value of '0 to the 0'.
    if (Pow == 1) return r;
    return pow<Pow - 1>(r) * r; 

}


Now, why do you want it - I doubt that it will buy you anything in terms of performance.
 
The issue is not particularly about performance,  it is about being able to do this at compile time; other than, well, trying out MPL. Your resolution to the problem is quite nice, though that's not what I am asking. My question is about MPL, not "how to do this with C++"... 
 
There should be a way of doing this using MPL with a single line of code. Or, even compute integer power of integers and get a compile time result. This is useful for many metaprograms and again, not a performance concern. 
 
Any ideas?
 
 
 
One more note. In my original post, I mentioned this constant sequence wrapper. If there were such a thing (is there?) then one could evaluate integer power of an integer at compile time. For instance:
 
const unsigned SIZE = 3;
const unsigned EIGHT  = fold ( constant_sequence< int_<2>, SIZE >, int_<1>, times< _ , _ > :: type :: value ;  
 
This is only a thought. Maybe there is a better way of computing powers, without using fold or that constant_sequence thingy..
 
As for the real powers, maybe there is a Boost.Fusion algorithm that can do it..
 
sami.