enum pointers or class references limitation

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 1 14:08:20 PDT 2017


On 09/01/2017 11:48 AM, Dmitry Olshansky wrote:
 > On Thursday, 31 August 2017 at 14:28:57 UTC, Ali Çehreli wrote:
 >> On 08/31/2017 01:52 AM, Nicholas Wilson wrote:
 >>
 >>> I think Timon is referring to:
 >>>
 >>> enum int[] foo = [1,2,3];
 >>>
 >>> auto bar = foo;
 >>> auto baz = foo;
 >>>
 >>> assert(!(bar is baz)); // Passes
 >>
 >> Even better:
 >>
 >>     enum int[] foo = [1,2,3];
 >>     assert(!(foo is foo)); // Passes
 >>
 >
 > I guess
 >
 > assert(!([1,2,3] is [1,2,3]));
 >
 > Which is exactly what enum expands to and totally expected. Where is the
 > surprise?

In the surprising case foo is a symbol, seemingly of a variable. Failing 
the 'is' test is surprising in that case. I've just remembered that the 
actual surprising case is the following explicit check:

     assert(!(foo.ptr is foo.ptr)); // Passes

I find it surprising because it looks like an entity does not have a 
well-behaving .ptr.

(Aside: I think your code might be surprising to at least newcomers as 
well.)

Ali



More information about the Digitalmars-d mailing list