On 09/21/2012 12:29 AM, Jonathan M Davis wrote:
...
In order for your foo function to be called, it must be fully compiled first
(including its entire body, since CTFE needs the full definition of the
function, not just its signature). The body cannot be fully compiled until the
template that it's using is instantiated. But that template can't be compiled
until foo has been compiled, because you're passing a call to foo to it as a
template argument. So, you have a circular dependency.
Normal recursion avoids this, because it only depends on the function's
signature, but what you're doing requires that the function be _run_ as part
of the process of defining it. That's an unbreakable circular dependency and
will never work. ...
It is not exactly unbreakable. This can work. Just delay spitting out
an error to the point the execution actually depends upon its own
result.