Why is length being tested on an int?

Adam D. Ruppe destructionator at gmail.com
Sat Oct 28 02:48:17 UTC 2017


On Saturday, 28 October 2017 at 02:38:43 UTC, Shriramana Sharma 
wrote:
>         if (is(typeof(arg) == string) && arg.length > 1)
> I am not sure why, given short circuit evaluation, it is 
> testing the length of the int argument?

That's a runtime check and therefore the code must run to be 
short circuited at all... which means it must compile the whole 
thing first.

Break the is() part into a separate static if, then put the 
runtime length check inside that. More like

static if(is(typeof(arg) == string)) {
     if(arg.length > 1)
          // handle
     else
          // string of short length
} else {
      // not a string
}


More information about the Digitalmars-d-learn mailing list