Is instantiabilty of templated types decidable?

Timon Gehr timon.gehr at gmx.ch
Sun Nov 11 10:37:45 PST 2012


On 11/11/2012 03:45 PM, Peter Alexander wrote:
> 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.

The possible inputs are finite, so the property is decidable.


More information about the Digitalmars-d mailing list