dropbox / json11

A tiny JSON library for C++11.
MIT License
2.55k stars 615 forks source link

Type conversion operators #44

Closed saur0n closed 8 years ago

saur0n commented 8 years ago

Why there are no operator int(), operator std::string(), operator bool() and others in Json class?

Amleto commented 8 years ago

Certainly I can see operator bool() being confusing/ambiguous.

saur0n commented 8 years ago

There is possibility to declare these operators explicit.

j4cbo commented 8 years ago

There's no operator bool because there's no obvious meaning for it. Javascript's semantics for truthiness are somewhat subtle (e.g. an empty string evaluates as false, but an empty array evaluates as true) and that's often a source of confusion. Being more explicit with is_null(), bool_value(), etc. makes code easier to read and write.

j4cbo commented 8 years ago

Er, replace "no obvious meaning" with "too many possible meanings" in the above

saur0n commented 8 years ago

But what about other operators (operator int(), operator std::string() etc)?