== 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;
> > }
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
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)
{
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
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
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
;
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
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
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
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
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
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
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
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
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
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
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).
17 matches
Mail list logo