From 5b50c1ebfeff842b93f92d6b5726ce4aa4becf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfram=20R=C3=B6sler?= Date: Thu, 5 Oct 2017 12:58:45 +0200 Subject: [PATCH] Allow non-deprecated removeMember/removeIndex with null return pointer Sometimes we just want to remove something we don't need anymore. Having to supply a return buffer for the removeMember/removeIndex function to return something we don't care about is a nuisance. There are remove- Member/Index functions that don't need a return pointer but they are deprecated. This commit allows the non-deprecated versions to be called with a null pointer as the last argument to simplify things for callers who don't need to get something back. For example: Json::Value j; j.removeMember("name"); // nice but deprecated Json::Value r; j.removeMember("name",&r); // possible but annoying j.removeMember("name",nullptr); // possible with this commit --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 2a53138bc..6511aaab3 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1175,7 +1175,7 @@ bool Value::removeMember(const char* key, const char* cend, Value* removed) ObjectValues::iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return false; - *removed = it->second; + if (removed) *removed = it->second; value_.map_->erase(it); return true; } @@ -1212,7 +1212,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) { if (it == value_.map_->end()) { return false; } - *removed = it->second; + if (removed) *removed = it->second; ArrayIndex oldSize = size(); // shift left all items left, into the place of the "removed" for (ArrayIndex i = index; i < (oldSize - 1); ++i){