From 3ca374516a5c205afcad35ce684e4dfee965df1b Mon Sep 17 00:00:00 2001 From: Jeramy Harrison Date: Wed, 20 Apr 2016 14:59:50 -0400 Subject: [PATCH] Added explicit operator bool() --- include/json/value.h | 3 +++ src/lib_json/json_value.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/include/json/value.h b/include/json/value.h index 4c29382b5..214b29ccb 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -385,6 +385,9 @@ Json::Value obj_value(Json::objectValue); // {} /// Return isNull() bool operator!() const; + /// Return !isNull() + explicit operator bool() const; + /// Remove all object members and array elements. /// \pre type() is arrayValue, objectValue, or nullValue /// \post type() is unchanged diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index e19559467..f05873f46 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -927,6 +927,8 @@ bool Value::empty() const { bool Value::operator!() const { return isNull(); } +Value::operator bool() const { return !isNull(); } + void Value::clear() { JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue || type_ == objectValue,