what is this kind of code?
so i found this code a while back and i cant make heads or tails of it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
template <unsigned int exponent>
inline double intpow(double base)
{
return intpow<exponent-1>(base) * base;
}
template <>
inline double intpow<0>(double base)
{
return 1;
}
int main()
{
cout << intpow<12>(1.2345) << " == " << pow(1.2345, 12) << endl;
}
|
obviously its templates of some kind, but lines 4 and and the second function confuse me
It's template meta-programming. I was going to try and explain it myself, but the wikipedia article does a much better job.
https://en.wikipedia.org/wiki/Template_metaprogramming
thanks. i think i understand. so in what cases can this be useful?
Topic archived. No new replies allowed.