EDIT: Richard Smith's finished answer.
There is no need to use metafunction according to your answer to implement your myPow algorithm as a constexpr -qualified function.
You can simply specify the exponent argument = 0, and then:
constexpr int myPow(int a, int b = 0){ return b == 0 ? 1 : myPow(a,b - 1) * a; }
If you do not like the default on this argument, then otherwise you can default this argument to the constexpr helper element, which myPow simply calls, for example,
namespace impl { constexpr int myPow(int a, int b = 0){ return b == 0 ? 1 : myPow(a,b - 1) * a; } } constexpr int myPow(int a, int b){ return impl::myPow(a,b); }
If and when you upgrade to at least gcc 4.7.2, you can -std=c++11 even to hide this auxiliary device inside myPow , because you will be allowed to define types inside the body of the constexpr function:
constexpr int myPow(int a, int b){ struct _1 { static constexpr int _2(int a, int b = 0) { return b == 0 ? 1 : _2(a,b - 1) * a; } }; return _1::_2(a,b); }
(although I think that strictly this latitude is an extension of C ++ 1y).
You might want to adapt the Vincent superior algorithm so that it is no longer a metaphone in N , but is still common to the arithmetic type.