Re: Is this actually supposed to be legal?

2012-07-18 Thread Timon Gehr
On 07/18/2012 01:37 AM, Jonathan M Davis wrote: On Tuesday, July 17, 2012 23:11:43 Timon Gehr wrote: This issue is unrelated to CRTP. (also, you probably want to negate that static if condition, otherwise the code is valid and poses no challenge to a compiler.) It's not that it makes the compi

Re: Is this actually supposed to be legal?

2012-07-18 Thread Timon Gehr
On 07/18/2012 11:08 PM, monarch_dodra wrote: On Tuesday, 17 July 2012 at 23:38:04 UTC, Jonathan M Davis wrote: It's not that it makes the compiler's life hard. It's the fact that conditional compilation relies on state that doesn't exist yet. It's messed up to be checking whether an object defin

Re: Is this actually supposed to be legal?

2012-07-18 Thread monarch_dodra
On Tuesday, 17 July 2012 at 23:38:04 UTC, Jonathan M Davis wrote: It's not that it makes the compiler's life hard. It's the fact that conditional compilation relies on state that doesn't exist yet. It's messed up to be checking whether an object defines something when you're in the middle of d

Re: Is this actually supposed to be legal?

2012-07-18 Thread Philippe Sigaud
> That being said, I have never used CRTP in D so far, since template mixins seem to be the better choice in almost all situations. FWIW, CRTP is the main reason I used classes in Pegged, to allow grammar rules to refer to themselves. My earlier attempts with structs did not work. So, given a gra

Re: Is this actually supposed to be legal?

2012-07-17 Thread Jonathan M Davis
On Tuesday, July 17, 2012 23:11:43 Timon Gehr wrote: > This issue is unrelated to CRTP. (also, you probably want to negate > that static if condition, otherwise the code is valid and poses no > challenge to a compiler.) It's not that it makes the compiler's life hard. It's the fact that condition

Re: Is this actually supposed to be legal?

2012-07-17 Thread David Nadlinger
On Tuesday, 17 July 2012 at 20:50:41 UTC, Jonathan M Davis wrote: The problem is that if you have static ifs and the like in the base class which depends on compile time reflection of the derived class, you effectively have a recursive template definition. e.g. class MyBase(T) { static if(is(

Re: Is this actually supposed to be legal?

2012-07-17 Thread Timon Gehr
On 07/17/2012 10:50 PM, Jonathan M Davis wrote: On Tuesday, July 17, 2012 22:36:10 Timon Gehr wrote: 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

Re: Is this actually supposed to be legal?

2012-07-17 Thread Jonathan M Davis
On Tuesday, July 17, 2012 22:36:10 Timon Gehr wrote: > 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: > >>> > >>> ---

Re: Is this actually supposed to be legal?

2012-07-17 Thread Timon Gehr
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!M

Re: Is this actually supposed to be legal?

2012-07-17 Thread Sean Cavanaugh
On 7/17/2012 12: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!My

Re: Is this actually supposed to be legal?

2012-07-17 Thread Jonathan M Davis
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 > >

Re: Is this actually supposed to be legal?

2012-07-17 Thread David Nadlinger
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 C

Re: Is this actually supposed to be legal?

2012-07-17 Thread Tommi
There's a thorough explanation of how "incomplete types" work in C++: http://www.drdobbs.com/the-standard-librarian-containers-of-inc/184403814 And there's some more C++ related stuff: http://www.boost.org/doc/libs/1_50_0/doc/html/container/containers_of_incomplete_types.html I wouldn't know ab

Re: Is this actually supposed to be legal?

2012-07-16 Thread Chris NS
It is indeed supposed to work, and was actually touted as a common and lauded example way back in the day. However, with the advent of this-params for templates it seems less useful now (once they've been through the ringer a little more at least). I did use this-params to great effect in Zea

Re: Is this actually supposed to be legal?

2012-07-16 Thread Jonathan M Davis
On Tuesday, July 17, 2012 07:37:38 Alex Rønne Petersen wrote: > (Not sure if MySubB was meant to demonstrate anything; it's effectively > semantically equal to MySubA.) It's a simplification of an example in this question: http://stackoverflow.com/questions/11516066/d-inheriting-static-variables-

Re: Is this actually supposed to be legal?

2012-07-16 Thread Alex Rønne Petersen
On 17-07-2012 07:24, 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() {} but it compiles just fine. However, given the fact that MySubA isn't even properly defined unt

Re: Is this actually supposed to be legal?

2012-07-16 Thread Brad Roberts
http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern On 7/16/2012 10:24 PM, 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() > {} > ---

Is this actually supposed to be legal?

2012-07-16 Thread Jonathan M Davis
This code strikes me as being a bug: class MyBase(T) {} class MySubA : MyBase!MySubA {} class MySubB : MyBase!MySubB {} void main() {} but it compiles just fine. However, given the fact that MySubA isn't even properly defined until its base class has been defined, I don't se