alias of member from pointer to struct?
    Jarrett Billingsley 
    kb3ctd2 at yahoo.com
       
    Sat Apr 14 14:51:25 PDT 2007
    
    
  
"BCS" <ao at pathlink.com> wrote in message 
news:ce0a334393e38c94c9daebff03a at news.digitalmars.com...
> is their a clean way to do this?
>
> struct S
> {
> int i;
> int j;
> }
>
> S* s;
>
> static if(cond) alias s.i var;
> else alias s.j var;
>
> // use var for lots of things
>
> This is going to be in a performance bottle neck so it must resolve to 
> ideal code.
>
> Also this is supposed to be demonstrating D's ability to, along with other 
> things, remove redundancy so ideally only the actual symbol will appear in 
> the static if.
If the static if is not at global scope, you can make a variable that points 
to the member:
const bool pick = false;
struct S
{
    int i;
    int j;
}
void main()
{
    S* s;
    static if(pick)
        int* var = &s.i;
    else
        int* var = &s.j;
}
Once macros come out you should be able to make a macro that expands to s.i 
or s.j. 
    
    
More information about the Digitalmars-d-learn
mailing list