Why isn't ++x an lvalue in D?

Weed resume755 at mail.ru
Thu Jan 8 19:31:48 PST 2009


Bill Baxter пишет:
> Another thread just reminded me of something I use frequently in C++
> that doesn't work in D because ++x is not an lvalue:
> 
>    int x,N;
>   ...
>    ++x %= N;
> 
> So is there some deep reason for not making it an lvalue like in C++?
> 

++x is x+=1 in D:

void main() {
  int i =3;
  int N =2;
  (i+=1) %= N;
}


Error: i += 1 is not an lvalue.

C++:

int main()
{
 int i = 2;
 int N = 3;
 i+1 %= N;

 return 0;
}

error: lvalue required as left operand of assignment



More information about the Digitalmars-d mailing list