Is alias equality inconsistent?

Jonathan M Davis jmdavisProg at gmx.com
Fri May 13 18:37:36 PDT 2011


On 2011-05-13 17:28, Timon Gehr wrote:
> > The only value of is and static arrays that I can think of is if you can
> > use them to verify whether a dynamic array refers to a particular static
> > array. Other than that, what value do they add? If you're checking for
> > equality, then use ==. That one use case may make it useful to allow for
> > is in comparing static and dynamic arrays, but other than that, I don't
> > really see what is gives you when comparing static arrays.
> > 
> > - Jonathan M Davis
> 
> is on static arrays compares ptr and length too. So it is different from
> ==.

And of what value is that? == should already doing that before checking for 
equality on each of the elements, because if the ptr and length are identical, 
then there's no point checking the elements for equality. So, is doesn't add 
any benefit there, unless == is poorly implemented for static arrays.

Static arrays are value types, not reference types, so checking whether two of 
them refer to the same array makes no sense. Checking whether a dynamic array 
refers to a static array makes sense, but checking whether two static arrays 
are the same array does not. And since == should shortcut when comparing a 
static array to itself (heck, the compiler should be able to optimize the 
check out entirely and replace it with true), I don't see how using is on two 
static arrays does anything for you at all.

- Jonathan M Davis


More information about the Digitalmars-d mailing list