On Thu, Jul 24, 2014 at 03:54:20PM +0000, Pavel via Digitalmars-d-learn wrote: [...] > Guess what, here's a new snippet: > > import std.stdio; > import std.json; > > void main() { > scope(failure) writeln("FaILED!!"); > string jsonStr = `{ "name": "1", "type": "r" }`; > auto parsed = parseJSON(jsonStr).object; > writeln("fail" in parsed); > } > > Output is: > null > > WAT?! > > Ofcourse, writing like: > > writeln(cast(bool)("fail" in parsed)); > > Produces "false"... but why on earth boolean expression would output null?
It's not a boolean expression. The 'in' operator returns a pointer. Rationale: avoid double lookups, for example: if (auto ptr = "key" in assocArray) { doSomething(*ptr); } T -- The right half of the brain controls the left half of the body. This means that only left-handed people are in their right mind. -- Manoj Srivastava