multiple `alias this` suggestion

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 26 08:00:30 PDT 2017


On 4/24/17 12:52 PM, Carl Sturtivant wrote:
> 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.

I think you can appreciate that this doesn't scale. Imagine a case which 
has 2 or 3 optional alias this items.

-Steve


More information about the Digitalmars-d mailing list