Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread bearophile via Digitalmars-d-learn
Klb: Hello, I'd like to know if it's possible, using CTFE, mixin etc to convert a POD struct to a class at compile time. I remember Andrei planned to add this small thingie to Phobos, but it's still missing. Bye, bearophile

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
Not a direct answer, but the way I'd do this is to just use composition: class Foo { YourStruct _this; alias _this this; } boom, it'd work pretty well just like that...

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 17:43:03 UTC, Klb wrote: auto names = __traits(allMembers, S); Error: static variable _names_field_0 cannot be read at compile time. The problem there is names is a regular runtime variable and mixins need to use compile time stuff. If you make that enum

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 16, 2014 at 06:07:32PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: Not a direct answer, but the way I'd do this is to just use composition: class Foo { YourStruct _this; alias _this this; } boom, it'd work pretty well just like that... +1, simple answer to

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Klb via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 18:09:10 UTC, Adam D. Ruppe wrote: On Wednesday, 16 July 2014 at 17:43:03 UTC, Klb wrote: auto names = __traits(allMembers, S); Error: static variable _names_field_0 cannot be read at compile time. The problem there is names is a regular runtime variable

Re: Converting a POD struct to a class at compile-time ?

2014-07-16 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 16 July 2014 at 18:27:31 UTC, Klb wrote: On Wednesday, 16 July 2014 at 18:09:10 UTC, Adam D. Ruppe wrote: On Wednesday, 16 July 2014 at 17:43:03 UTC, Klb wrote: auto names = __traits(allMembers, S); Error: static variable _names_field_0 cannot be read at compile time. The