digitalmars.D - Using Classes as the KeyType (from the Docs)
- Andrej Mitrovic (43/43) Jun 20 2010 Hi,
- Steven Schveighoffer (4/7) Jun 21 2010 Yes, it's a typo. You should file a bug.
- Andrej Mitrovic (2/15) Jun 21 2010 Will do. But I think I've noticed some more errors in other places, mayb...
- Steven Schveighoffer (4/22) Jun 21 2010 That would be great thanks!
- Brad Roberts (3/20) Jun 21 2010 More small reports would be better than delayed big reports. Just file ...
- Andrej Mitrovic (3/24) Jun 21 2010 It shouldn't take long, maybe a few days or so (and there's probably not...
Hi,
There's an example in the docs about classes with a keytype which I don't fully
understand. Here's the code (taken from
http://www.digitalmars.com/d/2.0/arrays.html under "Using Classes as the
KeyType"):
------------------------------------------------------
class Foo
{
int a, b;
hash_t toHash() { return a + b; }
bool opEquals(Object o)
{ Foo f = cast(Foo) o;
return f && a == foo.a && b == foo.b;
}
int opCmp(Object o)
{ Foo f = cast(Foo) o;
if (!f)
return -1;
if (a == foo.a)
return b - foo.b;
return a - foo.a;
}
}
------------------------------------------------------
Shouldn't this be written like this instead?:
------------------------------------------------------
class Foo
{
int a, b;
hash_t toHash() { return a + b; }
bool opEquals(Object o)
{ Foo f = cast(Foo) o;
return f && a == f.a && b == f.b;
}
int opCmp(Object o)
{ Foo f = cast(Foo) o;
if (!f)
return -1;
if (a == f.a)
return b - f.b;
return a - f.a;
}
}
------------------------------------------------------
Notice I've replaced "foo" with "f"
Foo is the class, but there's no mention of "foo". I'm guessing it was a typo,
unless I'm missunderstanding something.
Jun 20 2010
On Sun, 20 Jun 2010 16:50:04 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Notice I've replaced "foo" with "f" Foo is the class, but there's no mention of "foo". I'm guessing it was a typo, unless I'm missunderstanding something.Yes, it's a typo. You should file a bug. -Steve
Jun 21 2010
Steven Schveighoffer Wrote:On Sun, 20 Jun 2010 16:50:04 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Will do. But I think I've noticed some more errors in other places, maybe I should try catching as many of them and then do a single report so they all get fixed in a single run.Notice I've replaced "foo" with "f" Foo is the class, but there's no mention of "foo". I'm guessing it was a typo, unless I'm missunderstanding something.Yes, it's a typo. You should file a bug. -Steve
Jun 21 2010
On Mon, 21 Jun 2010 12:18:47 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Steven Schveighoffer Wrote:That would be great thanks! -SteveOn Sun, 20 Jun 2010 16:50:04 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Will do. But I think I've noticed some more errors in other places, maybe I should try catching as many of them and then do a single report so they all get fixed in a single run.Notice I've replaced "foo" with "f" Foo is the class, but there's no mention of "foo". I'm guessing itwas atypo, unless I'm missunderstanding something.Yes, it's a typo. You should file a bug. -Steve
Jun 21 2010
On 6/21/2010 9:18 AM, Andrej Mitrovic wrote:Steven Schveighoffer Wrote:More small reports would be better than delayed big reports. Just file as you find 'em.On Sun, 20 Jun 2010 16:50:04 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Will do. But I think I've noticed some more errors in other places, maybe I should try catching as many of them and then do a single report so they all get fixed in a single run.Notice I've replaced "foo" with "f" Foo is the class, but there's no mention of "foo". I'm guessing it was a typo, unless I'm missunderstanding something.Yes, it's a typo. You should file a bug. -Steve
Jun 21 2010
Brad Roberts Wrote:On 6/21/2010 9:18 AM, Andrej Mitrovic wrote:It shouldn't take long, maybe a few days or so (and there's probably not *that* many errors, but I have noticed some). Anyways I'll start hunting.Steven Schveighoffer Wrote:More small reports would be better than delayed big reports. Just file as you find 'em.On Sun, 20 Jun 2010 16:50:04 -0400, Andrej Mitrovic <andrej.mitrovich gmail.com> wrote:Will do. But I think I've noticed some more errors in other places, maybe I should try catching as many of them and then do a single report so they all get fixed in a single run.Notice I've replaced "foo" with "f" Foo is the class, but there's no mention of "foo". I'm guessing it was a typo, unless I'm missunderstanding something.Yes, it's a typo. You should file a bug. -Steve
Jun 21 2010









"Steven Schveighoffer" <schveiguy yahoo.com> 