CTFE calling a template: Error: expression ... is not a valid template value argument

Timon Gehr timon.gehr at gmx.ch
Thu Sep 20 16:20:10 PDT 2012


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.


More information about the Digitalmars-d mailing list