Is "is" the same as ptr == ptr for arrays?
simendsjo
simen.endsjo at pandavre.com
Sat Aug 7 09:07:24 PDT 2010
On 07.08.2010 18:04, Peter Alexander wrote:
> On 7/08/10 4:33 PM, simendsjo wrote:
>> Is the following equalent?
>>
>> int[] a;
>> int[] b = a;
>> assert(a is b);
>> assert(a.ptr == b.ptr);
>
> No.
>
> (a is b) implies (a.ptr == b.ptr)
>
> but
>
> (a.ptr == b.ptr) does not imply (a is b)
>
> For example:
>
> int[] a = [1, 2, 3];
> int[] b = a[0..1];
>
> Here, a.ptr == b.ptr, but a !is b.
>
> The ptr property returns a pointer to the first element, which is true
> in this case, but it doesn't mean that they both refer to the same range.
Ok, thanks. Does this mean this equivalent then?
int[] a = [1,2,3];
int[] b = a[0..1];
assert(a !is b);
assert(a.ptr == b.ptr && a.length == b.length);
More information about the Digitalmars-d-learn
mailing list