Getting the initial value of a class field in compile time.
    realhet 
    real_het at hotmail.com
       
    Sun Feb  9 00:57:05 UTC 2020
    
    
  
On Sunday, 9 February 2020 at 00:41:12 UTC, realhet wrote:
> On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote:
Using what I've learned:
class A{
   int i=42;
   void init(){ // reInitialize class fields
     alias T = typeof(this);
     mixin([FieldNameTuple!T].map!(n => n~"=(new T)."~n~";").join);
   }
}
(I also like to live dangerously with string mixins :D)
    
    
More information about the Digitalmars-d-learn
mailing list