digitalmars.D.bugs - [Issue 346] New: 'is' operator inconsistant with arrays
- d-bugmail puremagic.com (34/34) Sep 12 2006 http://d.puremagic.com/issues/show_bug.cgi?id=346
- d-bugmail puremagic.com (10/10) Sep 12 2006 http://d.puremagic.com/issues/show_bug.cgi?id=346
- Jarrett Billingsley (6/15) Sep 12 2006 I'd say that this is proper, but just a fuzzy area. == compares the val...
- d-bugmail puremagic.com (7/7) Sep 12 2006 http://d.puremagic.com/issues/show_bug.cgi?id=346
- d-bugmail puremagic.com (6/11) Sep 12 2006 http://d.puremagic.com/issues/show_bug.cgi?id=346
http://d.puremagic.com/issues/show_bug.cgi?id=346
Summary: 'is' operator inconsistant with arrays
Product: D
Version: 0.166
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P3
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: ibisbasenji gmail.com
It has been my understanding that the 'is' operator, when working with types
other than objects, is an alias for the '==' operator. (For template
simplicity, as I recall.) However, the following code illustrates a case where
it is different in behavior. (My apologies if this is not really a bug, but I
don't know what else to call it.)
--------------------------------------------------
import std .stdio ;
void main () {
static int[] foo = [1, 2, 3] ,
bar = [1, 2, 3] ;
int[] def = foo;
if (foo == bar) writefln(" foo == bar");
if (foo is bar) writefln(" foo is bar");
if (foo == def) writefln(" foo == def");
if (foo is def) writefln(" foo is def");
}
--------------------------------------------------
Outputs:
foo == bar
foo == def
foo is def
--
Sep 12 2006
http://d.puremagic.com/issues/show_bug.cgi?id=346
bugzilla digitalmars.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
"==" means the contents of the array are the same. "is" means the arrays occupy
the same location in memory. The program is behaving as expected.
--
Sep 12 2006
<d-bugmail puremagic.com> wrote in message news:bug-346-3 http.d.puremagic.com/issues/...http://d.puremagic.com/issues/show_bug.cgi?id=346It has been my understanding that the 'is' operator, when working with types other than objects, is an alias for the '==' operator. (For template simplicity, as I recall.) However, the following code illustrates a case where it is different in behavior. (My apologies if this is not really a bug, but I don't know what else to call it.)I'd say that this is proper, but just a fuzzy area. == compares the values of the arrays, and 'is' sees if the array references refer to the same data. The same way as class instances: == compares the values (using opEquals), and 'is' sees if they point to the same instance.
Sep 12 2006
http://d.puremagic.com/issues/show_bug.cgi?id=346 Fair enough, and that does make sense. Although, having experimented a little further, I see that 'is' is using the .ptr of the arrays (logical). This means that any slice which begins at index 0 will also match true to an 'is'. Much to be considered when writing templates with arrays in mind. --
Sep 12 2006
http://d.puremagic.com/issues/show_bug.cgi?id=346Fair enough, and that does make sense. Although, having experimented a little further, I see that 'is' is using the .ptr of the arrays (logical). This means that any slice which begins at index 0 will also match true to an 'is'. Much to be considered when writing templates with arrays in mind.Gah, no, I retract that. It does check the other properties, just in case. This is good. :) I can work with that. --
Sep 12 2006









d-bugmail puremagic.com 