I found a code here Printing 1 to 1000 without loop or conditionals
Can someone please explain how compile time recursion works, couldn\'t find it in google
This is not guaranteed to be pure compile-time recursion. The compiler will have to instantiate function f1()
for all parameters value from 2 to 1000 and they will call each other.
Then the compiler might see that those calls can be just turned into a sequence of cout << ...
statements. Maybe it eliminates calls, maybe not - this is up to the compiler. From the point of C++ this is a chain of function calls and the compiler can do whatever as long as it doesn't alter behavior.