I have code roughly like the following:

   dstring str = "name"d;
uint ordinal = (( str in Decls.ordinals ) !is null) ? Decls.ordinals[ str ] : -1;

struct Decls
   {
   uint[ dstring]   ordinals;
   }

//and
   Decls.ordinals[ str ] = ordinal_counter++;

The problem is that it always returns ordinal== -1 from the expression. Can you sort me out? I took this from the example given in the language reference under arrays, testing for membership (or similar, I forget the subssection title).

From good old printfs it seems to be the case that the array is being populated (elsewhere) with the expected correct values. Taking out the if doesn’t seem to help either. I don’t have a way of examining the contents of the dynamic array directly to check that they are actually being stored as expected, other than seeing that that line of code is indeed being executed with the expected values of str going in. Note that I’m using 32-bit dstrings everywhere, not strings of bytes.

Reply via email to