I may have got this wrong, but I thought that stuff marked with the keyword constexpr had to be known at compile time.
Then why in my example below, where I pass to the constexpr function a value that is only know at run time, I don't get any errors?!
size_t fib(size_t n)
{
if (n <= 1)
{
return 1;
}
return fib(n - 1) + fib(n - 2);
}
constexpr size_t fib_constexpr(size_t n)
{
if (n <= 1)
{
return 1;
}
return fib(n - 1) + fib(n - 2);
}
int main()
{
int n;
cin >> n;
cout << fib(n) << endl;
cout << fib_constexpr(n) << endl;
return 0;
}