Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
December 03, 2014 Is this a bug or am I doing something wrong? | ||||
---|---|---|---|---|
| ||||
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? |
December 03, 2014 Re: Is this a bug or am I doing something wrong? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drsneed | 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 |
December 03, 2014 Re: Is this a bug or am I doing something wrong? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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!
|
December 04, 2014 Re: Is this a bug or am I doing something wrong? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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
|
December 04, 2014 Re: Is this a bug or am I doing something wrong? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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 |
Copyright © 1999-2021 by the D Language Foundation