My thoughts & tries with rvalue references

Zach the Mystic reachzach at gggggmail.com
Sun Mar 31 17:26:17 PDT 2013


On Saturday, 30 March 2013 at 14:37:11 UTC, Namespace wrote:
> That's nice to hear. I was afraid I would be too intrusive on 
> this.
> And I've finally did it: A& works now. It was a bit tricky, but 
> now it works nicely. Here a quick example:
>
> void bar1(A& a) { } // OK
> void bar2(A&* a) { } // Error: '&' can not be used in 
> combination with '*'
> void bar3(A*& a) { } // Error: '&' can not be used in 
> combination with '*'
> void bar4(const A& a) { } // OK
> void bar5(ref A& a) { } // Error: conflicting storage class '&' 
> and ref
>
> and for templates:
>
> void bar(T)(T& t) {
> 	writeln(t);
> }
>
> Thoughts?

It's esoteric, which is bad, but concise, which is good. I think 
perhaps the annoying aspect of this feature is how attractive it 
would be to just get the power of the feature implicitly without 
needing a new attribute or keyword. To get it implicitly, and 
only have an attribute for when you *don't want an rvalue, e.g.:

void foo(@lvalue ref T a) {}

...would break code, but is nonetheless less something to 
consider also.



More information about the Digitalmars-d mailing list