On Friday, 30 June 2023 at 19:05:23 UTC, Cecil Ward wrote:
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?

Impossible to tell without a complete repro, I'm afraid. The expression, at least, looks correct at first glance.

Note that you can do `uint ordinal = Decls.ordinals.get(str, -1);`.

Reply via email to