STYLE: Use range-based loops from C++11

C++11 Range based for loops can be used in

Used as a more readable equivalent to the traditional for loop operating over a
range of values, such as all elements in a container, in the forward direction..

Range based loopes are more explicit for only computing the
end location once for containers.

SRCDIR=/Users/johnsonhj/src/jsoncpp/ #My local SRC
BLDDIR=/Users/johnsonhj/src/jsoncpp/cmake-build-debug/ #My local BLD

cd /Users/johnsonhj/src/jsoncpp/cmake-build-debug/
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-loop-convert  -header-filter=.* -fix
This commit is contained in:
Hans Johnson
2019-01-14 17:09:12 -06:00
committed by Hans Johnson
parent 3beadff472
commit cbeed7b076
5 changed files with 11 additions and 28 deletions

View File

@@ -1655,8 +1655,7 @@ void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {
const Value& Path::resolve(const Value& root) const {
const Value* node = &root;
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
const PathArgument& arg = *it;
for (const auto & arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
// Error: unable to resolve path (array value expected at position...
@@ -1681,8 +1680,7 @@ const Value& Path::resolve(const Value& root) const {
Value Path::resolve(const Value& root, const Value& defaultValue) const {
const Value* node = &root;
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
const PathArgument& arg = *it;
for (const auto & arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_))
return defaultValue;
@@ -1700,8 +1698,7 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const {
Value& Path::make(Value& root) const {
Value* node = &root;
for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
const PathArgument& arg = *it;
for (const auto & arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray()) {
// Error: node is not an array at position ...