www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - tupleof.length of a class in a template return 0

reply =?UTF-8?B?Ik1pY2hhw6ts?= Larouche" <michael.larouche gmail.com> writes:
I've given a second chance to D after watching D videos from 
Lang.NEXT 2012. As a first look, I wanted to try generate 
serialization code at compile time.

Here's the class:
class MyObject
{
     public int m_id;
     public Data m_data;
     public bool AutoDelete;
     public int RefCount;

mixin(AddStreamSerialization!(MyObject));
}
Apr 16 2012
next sibling parent reply =?UTF-8?B?Ik1pY2hhw6ts?= Larouche" <michael.larouche gmail.com> writes:
On Monday, 16 April 2012 at 23:58:29 UTC, Michaël Larouche wrote:
 I've given a second chance to D after watching D videos from 
 Lang.NEXT 2012. As a first look, I wanted to try generate 
 serialization code at compile time.

 Here's the class:
 class MyObject
 {
     public int m_id;
     public Data m_data;
     public bool AutoDelete;
     public int RefCount;

 mixin(AddStreamSerialization!(MyObject));
 }

Sorry I hit the send button. My template works with a struct but when I try to mixin my template in a class, I get compile error because T.tupleof.length returns 0. Here's the whole code: http://ideone.com/UR6YU
Apr 16 2012
parent Somedude <lovelydear mailmetrash.com> writes:
Le 19/04/2012 05:04, "Michaël Larouche" <michael.larouche gmail.com>" a
écrit :
 
 Reading the bug thread, I am wondering why my template worked in a
 struct but not inside a class.
 
 Anyway, I decided to move my mixin outside the struct/class and abuse
 UFCS instead. Now everything works like a charm :)

Cool. Glad it helpted. :)
Apr 19 2012
prev sibling next sibling parent "SomeDude" <lovelydear mailmetrash.com> writes:
On Tuesday, 17 April 2012 at 00:04:16 UTC, Michaël Larouche 
wrote:
 My template works with a struct but when I try to mixin my 
 template in a class, I get compile error because 
 T.tupleof.length returns 0.

 Here's the whole code:
 http://ideone.com/UR6YU

For what it's worth, dmd 2.059 (it seems you are using v2.042) gives this message: serial.d(21): Error: class serial.MyObject no size yet for forward reference serial.d(11): Error: template instance serial.GenerateFieldSerialization!(MyObject,0,"m_id","m_data","AMethod","AutoDelete","AnotherMethod","RefCount","Method1","toString","toHash","opCmp","opEquals", Monitor","factory") error instantiating According to Kenji Hara, "tupleof property requires complete semantic analysis to get the fields of a type." http://d.puremagic.com/issues/show_bug.cgi?id=7249 If you haven't solved your problem yet, you may try the workaround described or have a look at the result of googling this: "no size yet for forward reference" site:digitalmars.com/d
Apr 18 2012
prev sibling parent =?UTF-8?B?Ik1pY2hhw6ts?= Larouche" <michael.larouche gmail.com> writes:
On Wednesday, 18 April 2012 at 16:56:39 UTC, SomeDude wrote:
 On Tuesday, 17 April 2012 at 00:04:16 UTC, Michaël Larouche 
 wrote:
 My template works with a struct but when I try to mixin my 
 template in a class, I get compile error because 
 T.tupleof.length returns 0.

 Here's the whole code:
 http://ideone.com/UR6YU

For what it's worth, dmd 2.059 (it seems you are using v2.042) gives this message: serial.d(21): Error: class serial.MyObject no size yet for forward reference serial.d(11): Error: template instance serial.GenerateFieldSerialization!(MyObject,0,"m_id","m_data","AMethod","AutoDelete","AnotherMethod","RefCount","Method1","toString","toHash","opCmp","opEquals", Monitor","factory") error instantiating According to Kenji Hara, "tupleof property requires complete semantic analysis to get the fields of a type." http://d.puremagic.com/issues/show_bug.cgi?id=7249 If you haven't solved your problem yet, you may try the workaround described or have a look at the result of googling this: "no size yet for forward reference" site:digitalmars.com/d

Reading the bug thread, I am wondering why my template worked in a struct but not inside a class. Anyway, I decided to move my mixin outside the struct/class and abuse UFCS instead. Now everything works like a charm :)
Apr 18 2012