On Wednesday, 3 December 2014 at 23:09:02 UTC, Ali Çehreli wrote:
On 12/03/2014 03:02 PM, drsneed wrote:
Check out http://dpaste.dzfl.pl/a5ada78fccf5
If my function named "IWillNotCompile" is run, I get an error
stating
"Component!int' and 'Component!int' are not compatible."
If my function named "IWillCompile" is run, there are no
errors. They do
the same thing, just written slightly differently.
Any suggestions?
Unlike C++, rvalues cannot be bound to reference parameters
even if reference to const.
Make the parameter 'auto ref' and it will compile:
Component!(T) opBinary(string op)(auto ref Component!(T) rhs)
For auto ref, the function must be a template so that the
compiler can generate by-reference and by-value versions of it
depending on whether the argument is lvalue versus rvalue.
Here is my understanding of the issue:
http://ddili.org/ders/d.en/lvalue_rvalue.html
Ali
Ahh, I'm used to the c++ style. Nice write-up on the matter, and
thanks for the help!