| Thread overview | |||||
|---|---|---|---|---|---|
|
August 29, 2011 struct opEquals does not work with parameter of same type - bug or feature? | ||||
|---|---|---|---|---|
| ||||
I am trying to build a struct with equality testing, using this code:
struct Foo
{
const bool opEquals(Foo f)
{
return true;
}
}
This gives me the error that the parameter should be of type "ref const Foo". Fine.
struct Foo
{
const bool opEquals(ref const Foo f)
{
return true;
}
}
This, however, does not work with code like:
Foo bar()
{
return Foo();
}
assert(Foo() == bar());
"function Foo.opEquals(ref const const(Foo) f) const is not callable using
argument types (Foo)" and "bar() is not an lvalue".
How can I do this?
| ||||
August 30, 2011 Re: struct opEquals does not work with parameter of same type - bug or feature? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sean Eskapp | On Monday, August 29, 2011 22:41:26 Sean Eskapp wrote: > I am trying to build a struct with equality testing, using this code: > > struct Foo > { > const bool opEquals(Foo f) > { > return true; > } > } > > This gives me the error that the parameter should be of type "ref const Foo". Fine. > > struct Foo > { > const bool opEquals(ref const Foo f) > { > return true; > } > } > > This, however, does not work with code like: > > Foo bar() > { > return Foo(); > } > > assert(Foo() == bar()); > > "function Foo.opEquals(ref const const(Foo) f) const is not callable using > argument types (Foo)" and "bar() is not an lvalue". > > How can I do this? http://d.puremagic.com/issues/show_bug.cgi?id=3659 http://stackoverflow.com/questions/6986175/const-ref-and-rvalue-in-d - Jonathan M Davis | |||
August 30, 2011 Re: struct opEquals does not work with parameter of same type - bug or feature? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | == Quote from Jonathan M Davis (jmdavisProg@gmx.com)'s article
> On Monday, August 29, 2011 22:41:26 Sean Eskapp wrote:
> > I am trying to build a struct with equality testing, using this code:
> >
> > struct Foo
> > {
> > const bool opEquals(Foo f)
> > {
> > return true;
> > }
> > }
> >
> > This gives me the error that the parameter should be of type "ref const Foo". Fine.
> >
> > struct Foo
> > {
> > const bool opEquals(ref const Foo f)
> > {
> > return true;
> > }
> > }
> >
> > This, however, does not work with code like:
> >
> > Foo bar()
> > {
> > return Foo();
> > }
> >
> > assert(Foo() == bar());
> >
> > "function Foo.opEquals(ref const const(Foo) f) const is not callable using
> > argument types (Foo)" and "bar() is not an lvalue".
> >
> > How can I do this?
> http://d.puremagic.com/issues/show_bug.cgi?id=3659 http://stackoverflow.com/questions/6986175/const-ref-and-rvalue-in-d - Jonathan M Davis
Ah, thanks!
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply