#include <iostream>
using namespace std;
template <int fact>
constexpr int pow2T()
{
static_assert(fact < 0, "error");
return fact == 0 ? 1 : pow2T<fact - 1>() * 2;
}
constexpr int e2 = pow2T<2>();
int main(int argc, char *argv[])
{
cout << e2 << endl;
return 0;
}
Trying to implement x^2
static calculation with argument static checking.
Assertion fails.. why!?
/home/serj/work/untitled/main.cpp:-1: In function 'constexpr int pow2T() [with int fact = 2]':
/home/serj/work/untitled/main.cpp:-1: In function 'constexpr int pow2T() [with int fact = 1]':
...