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

Rene Zwanenburg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 16 15:03:09 PDT 2014


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 problem there is names is a regular runtime variable and 
>> mixins need to use compile time stuff. If you make that enum 
>> instead of auto, it'll probably work.
>
> Unfortunately I can't encapsulate and alias. Behind the 
> question stands another idea: I do something with an interface 
> implementer, as the "something" is not compat. with structs the 
> idea was to generate a class as a string, with the interface 
> and its default method...

If I understand you correctly, 'wrap' may be what you're looking 
for:

http://dlang.org/library/std/typecons/wrap.html


More information about the Digitalmars-d-learn mailing list