www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is this a bug or am I doing something wrong?

reply "drsneed" <dustin.sneeden gmail.com> writes:
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?
Dec 03 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Dec 03 2014
next sibling parent "drsneed" <dustin.sneeden gmail.com> writes:
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!
Dec 03 2014
prev sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 12/3/14 6:09 PM, 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
All that being said, what a horrible error message! -Steve
Dec 04 2014
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 12/04/2014 06:37 AM, Steven Schveighoffer wrote:

 All that being said, what a horrible error message!
https://issues.dlang.org/show_bug.cgi?id=13818 Ali
Dec 04 2014