Allow this() { } for structs

Q. Schroll qs.il.paperinik at gmail.com
Mon Nov 2 19:53:31 UTC 2020


In metaprogramming, I find myself writing stuff like

     struct S(Ts...)
     {
         this(Ts args)
         {
             static foreach (T; Ts) { /*...*/ }
         }
     }

and get compiler errors for the case that `Ts` is empty. So I 
need an actually useless

     static if (Ts.length != 0)
     this(Ts args) { /*...*/ }

Can we just allow this() when the body is essentially empty (that 
is: after rewrites and lowerings contains no statements)? The 
compiler would happily accept the code and pretend this() { } 
isn't there. It would even reduce confusion because S() is legal 
as an expression, but this() isn't as a constructor. With that, 
this() is legal as a constructor, but it must not do anything.


More information about the Digitalmars-d mailing list