My thoughts & tries with rvalue references

Namespace rswhite4 at googlemail.com
Fri Mar 29 06:45:47 PDT 2013


Hey guys,
I would like to show you my tries and thoughts about rvalue 
references and their syntax.
As discussed in my other thread in the learn group 
(http://forum.dlang.org/thread/uswucstsooghescofycp@forum.dlang.org?page=2#post-mailman.294.1364252397.4724.digitalmars-d-learn:40puremagic.com), 
auto ref is not longer an option for non-template functions.
Because of that I learned to read the compiler code and start my 
own tries, as you can read in my thread also 
(http://forum.dlang.org/thread/uswucstsooghescofycp@forum.dlang.org?page=3#post-jrksuqqremsqgicmybri:40forum.dlang.org).
One of my tries was a kind of pseudo-property "@ref" and finally 
a hybrid of D and C++: ref&.
Because I think a property isn't the best solution, I like to 
hear your thougths about my idea with "ref&".
Here a small example:

void bar1(ref& A a) { } // OK
void bar2(ref &A a) { } // OK
void bar21(&A a) { } // Error: '&' can only be used in 
combination with 'ref'.
void bar22(& A a) { } // Error: '&' can only be used in 
combination with 'ref'.
void bar3(ref const& A a) { } // OK
void bar4(ref const &A a) { } // OK
void bar5(ref &const A a) { } // Error: '&' Must be directly used 
in front of the type.
void bar6(ref& const A a) { } // Error: '&' Must be directly used 
in front of the type.

And for templates:

void foo(T)(ref &T t) { }

As you can see, '&' can only be used in front of the type and 
cannot exist without 'ref'.

The advantages of this syntax would be:
  - it is short
  - It is easy to implement
  - it is known from C++
  - It does not cause conflicts with other things
and it is (IMO) a very nice hybrid of C++ ref and D ref.

Hope you like it, just like me. But I would like to hear your 
general opinions about it.
Thanks in advance.


More information about the Digitalmars-d mailing list