Is this an rvalue reference problem?

tsbockman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 27 10:53:38 PST 2015


On Sunday, 27 December 2015 at 16:05:39 UTC, Gary Willoughby 
wrote:
> If I remove the post-increment of the y variable if works. Is 
> this an rvalue reference issue? Would you expect this to work?

This should work with *pre*-increment, but not post-increment. 
Post-increment works like this:

int y = 0;
foo(function(ref int val){
     int old = val;
     val += 1;
     return old;
}(y));

`old` is just a local temporary, so it is not safe to return it 
by reference. Thus, it becomes an rvalue.


More information about the Digitalmars-d-learn mailing list