File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed
Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -400,8 +400,8 @@ Json::Value obj_value(Json::objectValue); // {}
400400 // / otherwise, false.
401401 bool empty () const ;
402402
403- // / Return isNull()
404- bool operator ! () const ;
403+ // / Return ! isNull()
404+ explicit operator bool () const ;
405405
406406 // / Remove all object members and array elements.
407407 // / \pre type() is arrayValue, objectValue, or nullValue
Original file line number Diff line number Diff line change @@ -962,7 +962,7 @@ bool Value::empty() const {
962962 return false ;
963963}
964964
965- bool Value::operator ! () const { return isNull (); }
965+ Value::operator bool () const { return ! isNull (); }
966966
967967void Value::clear () {
968968 JSON_ASSERT_MESSAGE (type_ == nullValue || type_ == arrayValue ||
Original file line number Diff line number Diff line change @@ -308,6 +308,12 @@ JSONTEST_FIXTURE(ValueTest, null) {
308308 JSONTEST_ASSERT_STRING_EQUAL (" " , null_.asString ());
309309
310310 JSONTEST_ASSERT_EQUAL (Json::Value::null, null_);
311+
312+ // Test using a Value in a boolean context (false iff null)
313+ JSONTEST_ASSERT_EQUAL (null_,false );
314+ JSONTEST_ASSERT_EQUAL (object1_,true );
315+ JSONTEST_ASSERT_EQUAL (!null_,true );
316+ JSONTEST_ASSERT_EQUAL (!object1_,false );
311317}
312318
313319JSONTEST_FIXTURE (ValueTest, strings) {
You can’t perform that action at this time.
0 commit comments