On Friday, 7 February 2020 at 08:52:44 UTC, mark wrote:
Some languages support this kind of thing:

if ((var x = expression) > 50)
  print(x, " is > 50")

Is there anything similar in D?

Yes and no.

It only works for bools or things that convert to bool.

You might have seen:

string[string] dict;
if (auto p = "key" in dict) {
  writeln(*p);
}

That works because the 'in' operator on aa's returns a pointer, which can be compared to bool.

Reply via email to