## digitalmars.D.learn - Is "is" the same as ptr == ptr for arrays?

• simendsjo (5/5) Aug 07 2010 Is the following equalent?
• Peter Alexander (11/16) Aug 07 2010 No.
• simendsjo (6/23) Aug 07 2010 Ok, thanks. Does this mean this equivalent then?
• Simen kjaeraas (5/10) Aug 07 2010 Well, no. But what you probably mean, is.
• BCS (5/17) Aug 07 2010 I think that is correct.
simendsjo <simen.endsjo pandavre.com> writes:
```Is the following equalent?

int[] a;
int[] b = a;
assert(a is b);
assert(a.ptr == b.ptr);
```
Aug 07 2010
Peter Alexander <peter.alexander.au gmail.com> writes:
```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.
```
Aug 07 2010
simendsjo <simen.endsjo pandavre.com> writes:
```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);
```
Aug 07 2010
"Simen kjaeraas" <simen.kjaras gmail.com> writes:
```simendsjo <simen.endsjo pandavre.com> wrote:

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);

Well, no. But what you probably mean, is.

( a is b ) == ( a.ptr == b.ptr && a.length == b.length )

--
Simen
```
Aug 07 2010
BCS <none anon.com> writes:
```Hello Simen,

simendsjo <simen.endsjo pandavre.com> wrote:

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);

Well, no.

both asserts will fail (a.length == 3 != b.length == 1)

But what you probably mean, is.

( a is b ) == ( a.ptr == b.ptr && a.length == b.length )

I think that is correct.

--
... <IXOYE><
```
Aug 07 2010