Re: struct opEquals does not work with parameter of same type - bug or feature?

2011-08-29 Thread Sean Eskapp
== Quote from Jonathan M Davis (jmdavisp...@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; > > }

Re: struct opEquals does not work with parameter of same type - bug or feature?

2011-08-29 Thread Jonathan M Davis
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

struct opEquals does not work with parameter of same type - bug or feature?

2011-08-29 Thread Sean Eskapp
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) {

Re: struct opEquals

2011-03-09 Thread Steven Schveighoffer
On Wed, 09 Mar 2011 12:15:26 -0500, SiegeLord wrote: Steven Schveighoffer Wrote: It's a mis-designed feature of structs. There is a bug report on it: http://d.puremagic.com/issues/show_bug.cgi?id=3659 It worked fine in D1. Or did you mean that the mis-designed feature is the const syste

Re: struct opEquals

2011-03-09 Thread SiegeLord
Steven Schveighoffer Wrote: > It's a mis-designed feature of structs. There is a bug report on it: > > http://d.puremagic.com/issues/show_bug.cgi?id=3659 It worked fine in D1. Or did you mean that the mis-designed feature is the const system? Anyway, thanks for the link to the bug report. I'l

Re: struct opEquals

2011-03-09 Thread Steven Schveighoffer
sert(S.New() == s); 2) Why is the type of struct opEquals have to be const bool opEquals(ref const(T) s)? Why is it even enforced to be anything in particular (it's not like there's an Object or something to inherit from)? It's a mis-designed feature of structs. There is

struct opEquals

2011-03-09 Thread SiegeLord
; assert(s == S.New); } 2) Why is the type of struct opEquals have to be const bool opEquals(ref const(T) s)? Why is it even enforced to be anything in particular (it's not like there's an Object or something to inherit from)? -SiegeLord

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
Inside free functions there can be a locally defined compile-time boolean constant like __used_return. If you use this constant inside a function the compiler creates two versions of the function that share the same static variables (if the function is a template then each pair of instantiated

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
bearophile Wrote: >> (time ago I have suggested for a compile time flag that's defined inside >> functions to know if their result is used, to avoid computing it in some >> situations, turning the single function in a kind of templated function, but >> I am not sure it can work well if you have

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
qwerty: > For a function without any side effects, it shouldn't be a problem.. I think > :) Ignoring the return value of a function without side effects (in D2 pure functions or nothrow pure functions) has to be an error. I even have a bug report for this, because it's the same situation as an

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
bearophile Wrote: > qwerty: > > If I return *this, I should also provide the *S version of opEquals? > > If you don't provide a necessary operator the compiler complaints. > > > > What happens with the return value if it isn't used? > > The function is one and it doesn't change, it has to be

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
qwerty: > If I return *this, I should also provide the *S version of opEquals? If you don't provide a necessary operator the compiler complaints. > What happens with the return value if it isn't used? The function is one and it doesn't change, it has to be the same for everyone that calls it

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
bearophile Wrote: > qwerty: > > My opEquals takes an Vec2 and not a *Vec2, is this wrong? > > It's OK. D1 docs say: > Structs and unions (hereafter just called structs) can provide a member > function: > int opEquals(S s) > or: > int opEquals(S* s) > > > > Why is return value of the rotate fun

Re: [D1] struct opEquals questions

2010-03-18 Thread qwerty
Lars T. Kyllingstad Wrote: > qwerty wrote: > > In my unittest I tried to test out my rotate function. > > assert(Vec2(1,2).rotate(90) == Vec(-2,1)); > > But I got these compile errors: > > vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match > > parameter types (void) > > vecto

Re: [D1] struct opEquals questions

2010-03-18 Thread Lars T. Kyllingstad
qwerty wrote: In my unittest I tried to test out my rotate function. assert(Vec2(1,2).rotate(90) == Vec(-2,1)); But I got these compile errors: vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match parameter types (void) vector.d(156): Error: cannot implicitly convert expressio

Re: [D1] struct opEquals questions

2010-03-18 Thread bearophile
qwerty: > My opEquals takes an Vec2 and not a *Vec2, is this wrong? It's OK. D1 docs say: Structs and unions (hereafter just called structs) can provide a member function: int opEquals(S s) or: int opEquals(S* s) > Why is return value of the rotate function compared and not the rotated > struc

[D1] struct opEquals questions

2010-03-18 Thread qwerty
In my unittest I tried to test out my rotate function. assert(Vec2(1,2).rotate(90) == Vec(-2,1)); But I got these compile errors: vector.d(156): Error: function vector.Vec.opEquals (Vec) does not match parameter types (void) vector.d(156): Error: cannot implicitly convert expression (opCall(1,2).