Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,22 @@ Json::Value obj_value(Json::objectValue); // {}
/// otherwise, false.
bool empty() const;

/// Return isNull()
bool operator!() const;
/** \brief Return ! isNull();
*
* Example of usage:
* \code
* Json::Value root;
* std::cin >> root;
*
* if (auto tag = root["tag"]) {
* // Behavior if tag object with tag key exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is probably overdoing it.
It's also got a grammatical problem and I don't like involving the behavior of operator[] into the explanation. Let's explain it without referring to other API points if we can.

* } else {
* // Behavior if tag object with tag key absent
* }
* \endcode
*
*/
explicit operator bool() const;

/// Remove all object members and array elements.
/// \pre type() is arrayValue, objectValue, or nullValue
Expand Down
2 changes: 1 addition & 1 deletion src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ bool Value::empty() const {
return false;
}

bool Value::operator!() const { return isNull(); }
Value::operator bool() const { return ! isNull(); }

void Value::clear() {
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue ||
Expand Down