Better way to achieve the following

Ali Çehreli acehreli at yahoo.com
Tue Jun 21 17:54:56 UTC 2022


On 6/21/22 10:09, JG wrote:
> Suppose we are often writing something like
> ```d
> theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]=x; 
> 
> ```
> One would like to something like
> ```d
> alias shortName = 
> theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex]; 
> 
> shortName = x;
> ```
> but you can't alias an expression.

An option is nested functions:

   ref shortName() {
     return 
theFirstName[theFirstIndex].theSecondName[theSecondIndex].thirdName[theThirdIndex];
   }

   shortName = x;

Ali


More information about the Digitalmars-d-learn mailing list