Is this actually supposed to be legal?

Timon Gehr timon.gehr at gmx.ch
Tue Jul 17 13:36:10 PDT 2012


On 07/17/2012 07:23 PM, Jonathan M Davis wrote:
> On Tuesday, July 17, 2012 14:48:32 David Nadlinger wrote:
>> On Tuesday, 17 July 2012 at 05:24:26 UTC, Jonathan M Davis wrote:
>>> This code strikes me as being a bug:
>>>
>>> --------
>>> class MyBase(T)
>>> {}
>>>
>>> class MySubA : MyBase!MySubA
>>> {}
>>>
>>> class MySubB : MyBase!MySubB
>>> {}
>>>
>>> void main()
>>> {}
>>> --------
>>
>> This pattern is actually quite common in C++ code, and referred
>> to as CRTP (curiously recurring template pattern). If you propose
>> to kill it, Andrei is going to get mad at you. ;)
>
> Well, it certainly seems insane to me at first glance - particularly when you
> take compile time reflection into account, since the derived classes'
> definitions are now effectively recursive (so I suspect that the situation is
> worse in D, since C++ doesn't have conditional compliation like D does).

The fact that it is allowed does not make the compiler's job
significantly more complicated. It is not important if the type is
passed as a template argument or referred to directly from inside the
template -- the issues are the same.


More information about the Digitalmars-d-learn mailing list