reuse function logic in a const expression
<p>I think my question is, is there anyway to emulate the behaviour that we'll gain from C++0x's <code>constexpr</code> keyword with the current C++ standard (that is if I understand what <code>constexpr</code> is supposed to do correctly).</p>

<p>To be more clear, there are times when it is useful to calculate a value at compile time but it is also useful to be able to calculate it at runtime too, for e.g. if we want to calculate powers, we could use the code below.</p>

<pre><code>template&lt;int X, unsigned int Y&gt;
struct xPowerY_const {
    static const int value = X*xPowerY_const&lt;X,Y-1&gt;::value;
};

template&lt;int X&gt;
struct xPowerY_const&lt;X, 1&gt; {
    static const int value = X;
};

int xPowerY(int x, unsigned int y) {
    return (y==1) ? x : x*xPowerY(x,y-1);
}
</code></pre>

<p>This is a simple example but in more complicated cases being able to reuse the code would be helpful. Even if, for runtime performance, the recursive nature of the function is suboptimal and a better algorithm could be devised it would be useful for testing the logic if the templated version could be expressed in a function, as I can't see a reasonable method of testing the validity of the constant template method in a wide range of cases (although perhaps there is one and i just can't see it, and perhaps that's another question).</p>

<p>Thanks.</p>

<p><strong>Edit</strong>
Forgot to mention, I don't want to <code>#define</code></p>

<p><strong>Edit2</strong> Also my code above is wrong, it doesn't deal with x^0, but that doesn't affect the question.</p>
