www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to compare immutable ints?

reply Charles Hixson <charleshixsn earthlink.net> writes:
(Sorry if this double posts.  I'm having trouble getting through at all.)

How should I compare immutable ints to ensure that they are actually equal?

I was quite surprised to receive the following error message:

cbt2.d(732): Error: function object.Object.opEquals (Object o) is not 
callable using argument types (immutable(int))

when I tried to assert that two values were equal.  They were (should 
be), indeed, immutable ints, but I'd prefer that I could check that they 
were equivalent without printing them both out.  (I'm having a bit of 
trouble keeping my logic straight, so I'm trying to assert many things 
that should obviously be true.  And sometimes I've been surprised.)

-- 
Charles Hixson
Jun 18 2013
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 18 Jun 2013 15:37:44 -0400, Charles Hixson  
<charleshixsn earthlink.net> wrote:

 (Sorry if this double posts.  I'm having trouble getting through at all.)

 How should I compare immutable ints to ensure that they are actually  
 equal?

 I was quite surprised to receive the following error message:

 cbt2.d(732): Error: function object.Object.opEquals (Object o) is not  
 callable using argument types (immutable(int))

 when I tried to assert that two values were equal.  They were (should  
 be), indeed, immutable ints, but I'd prefer that I could check that they  
 were equivalent without printing them both out.  (I'm having a bit of  
 trouble keeping my logic straight, so I'm trying to assert many things  
 that should obviously be true.  And sometimes I've been surprised.)
The error quoted above suggests you are trying to compare an object type with an int. Can you give some more context? You can do that, but you have to overload opEquals. -Steve
Jun 18 2013
next sibling parent Charles Hixson <charleshixsn earthlink.net> writes:
2nd attempted reply:
On 06/18/2013 12:40 PM, Steven Schveighoffer wrote:
 On Tue, 18 Jun 2013 15:37:44 -0400, Charles Hixson 
 <charleshixsn earthlink.net> wrote:

 (Sorry if this double posts.  I'm having trouble getting through at 
 all.)

 How should I compare immutable ints to ensure that they are actually 
 equal?

 I was quite surprised to receive the following error message:

 cbt2.d(732): Error: function object.Object.opEquals (Object o) is not 
 callable using argument types (immutable(int))

 when I tried to assert that two values were equal.  They were (should 
 be), indeed, immutable ints, but I'd prefer that I could check that 
 they were equivalent without printing them both out.  (I'm having a 
 bit of trouble keeping my logic straight, so I'm trying to assert 
 many things that should obviously be true.  And sometimes I've been 
 surprised.)
The error quoted above suggests you are trying to compare an object type with an int. Can you give some more context? You can do that, but you have to overload opEquals. -Steve
Thanks. That was the answer I couldn't see. I read it as complaining about comparing two immutable ints, but assert (nodes[root2.pg.pgNo] == root2.pg.pgNo); should have read assert (nodes[root2.pg.pgNo].pg.pgNo == root2.pg.pgNo); -- Charles Hixson
Jun 18 2013
prev sibling next sibling parent Charles Hixson <charleshixsn earthlink.net> writes:
3rd or 4th try:
On 06/18/2013 12:40 PM, Steven Schveighoffer wrote:
 On Tue, 18 Jun 2013 15:37:44 -0400, Charles Hixson 
 <charleshixsn earthlink.net> wrote:

 (Sorry if this double posts.  I'm having trouble getting through at 
 all.)

 How should I compare immutable ints to ensure that they are actually 
 equal?

 I was quite surprised to receive the following error message:

 cbt2.d(732): Error: function object.Object.opEquals (Object o) is not 
 callable using argument types (immutable(int))

 when I tried to assert that two values were equal.  They were (should 
 be), indeed, immutable ints, but I'd prefer that I could check that 
 they were equivalent without printing them both out.  (I'm having a 
 bit of trouble keeping my logic straight, so I'm trying to assert 
 many things that should obviously be true.  And sometimes I've been 
 surprised.)
The error quoted above suggests you are trying to compare an object type with an int. Can you give some more context? You can do that, but you have to overload opEquals. -Steve
-- Charles Hixson
Jun 18 2013
prev sibling parent Charles Hixson <charleshixsn earthlink.net> writes:
On 06/18/2013 12:40 PM, Steven Schveighoffer wrote:
 On Tue, 18 Jun 2013 15:37:44 -0400, Charles Hixson 
 <charleshixsn earthlink.net> wrote:

 (Sorry if this double posts.  I'm having trouble getting through at 
 all.)

 How should I compare immutable ints to ensure that they are actually 
 equal?

 I was quite surprised to receive the following error message:

 cbt2.d(732): Error: function object.Object.opEquals (Object o) is not 
 callable using argument types (immutable(int))

 when I tried to assert that two values were equal.  They were (should 
 be), indeed, immutable ints, but I'd prefer that I could check that 
 they were equivalent without printing them both out.  (I'm having a 
 bit of trouble keeping my logic straight, so I'm trying to assert 
 many things that should obviously be true.  And sometimes I've been 
 surprised.)
The error quoted above suggests you are trying to compare an object type with an int. Can you give some more context? You can do that, but you have to overload opEquals. -Steve
Thanks. That was the answer I couldn't see. I read it as complaining about comparing two immutable ints, but assert (nodes[root2.pg.pgNo] == root2.pg.pgNo); should have read assert (nodes[root2.pg.pgNo].pg.pgNo == root2.pg.pgNo); -- Charles Hixson
Jun 18 2013