Is this actually supposed to be legal?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 17 10:23:52 PDT 2012
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). But
if it's supposed to be legal, I guess that it's suppose to be legal. I'd never
seen the idiom before, and it seemed _really_ off to me, which is why I brought
it up. But I'd have to study it in order to give an informed opinion on it.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list