multiple `alias this` suggestion

Carl Sturtivant via Digitalmars-d digitalmars-d at puremagic.com
Mon Apr 24 09:52:49 PDT 2017


On Friday, 21 April 2017 at 14:55:31 UTC, Steven Schveighoffer 
wrote:
> I agree, I like how this solves the ambiguity problem nicely. 
> However, this disallows using introspection to declare multiple 
> alias this piecemeal. e.g.:
>
> struct S(bool foo)
> {
>   int x;
>   alias x this;
>   static if(foo)
>   {
>      string y;
>      alias y this;
>   }
> }
>
> One thing we can do also is just use declaration order to 
> prioritize which alias this to use.

Not necessary in this case:

struct S(bool foo)
{
   int x;
   static if(!foo)
   {
      alias x this;
   }
   else
   {
      string y;
      alias x, y this;
   }
}

It's easier to analyze if  isn't distributed, i.e. if only one 
location applies.



More information about the Digitalmars-d mailing list