Is instantiabilty of templated types decidable?

Peter Alexander peter.alexander.au at gmail.com
Sun Nov 11 06:45:45 PST 2012


On Sunday, 11 November 2012 at 13:40:45 UTC, evansl wrote:
> On 11/11/12 06:49, Peter Alexander wrote:
>> On Sunday, 11 November 2012 at 12:33:25 UTC, Manfred Nowak 
>> wrote:
>>> a) Instantiability is decidable
>>> Why does the compiler stop with the evaluation at that 
>>> randomly
>>> choosen and apparently hard coded value of 500 recursive
>>> expansions?
>> 
>> It's not decidable. Consider use of static if. It's Turing 
>> complete. I
>> can give an example if you like.
>> 
>
> I'd like.  An example might help me better understand why it's
> undecidable.
> [snip]

Collatz sequence.

struct Collatz(int n)
{
     enum next = n % 2 == 0 ? n / 2 : 3 * n + 1;
     Collatz!(next)* foo;
}

It's an unsolved problem in mathematics whether or not this 
instantiates an infinite number of templates.


More information about the Digitalmars-d mailing list