From 9e5b479b9516e9706c306fd8fb152fc856aae633 Mon Sep 17 00:00:00 2001 From: Chris Brumgard Date: Thu, 18 May 2023 10:11:37 -0400 Subject: [PATCH] Fixed validation_visitor to work with adaptors that only support the forward_iterator_tag for array value iterators. --- include/valijson/validation_visitor.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/valijson/validation_visitor.hpp b/include/valijson/validation_visitor.hpp index 260152b..d4b2f31 100644 --- a/include/valijson/validation_visitor.hpp +++ b/include/valijson/validation_visitor.hpp @@ -1208,8 +1208,10 @@ public: return true; } + size_t array_size = m_target.getArraySize(); + // Empty arrays are always valid - if (m_target.getArraySize() == 0) { + if (array_size == 0) { return true; } @@ -1217,10 +1219,9 @@ public: const typename AdapterType::Array targetArray = m_target.asArray(); const typename AdapterType::Array::const_iterator end = targetArray.end(); - const typename AdapterType::Array::const_iterator secondLast = --targetArray.end(); - unsigned int outerIndex = 0; + typename AdapterType::Array::const_iterator outerItr = targetArray.begin(); - for (; outerItr != secondLast; ++outerItr) { + for (unsigned int outerIndex = 0; outerIndex < array_size - 1 /*outerItr != secondLast*/; ++outerItr) { unsigned int innerIndex = outerIndex + 1; typename AdapterType::Array::const_iterator innerItr(outerItr); for (++innerItr; innerItr != end; ++innerItr) { @@ -1239,7 +1240,7 @@ public: return validated; } - + private: /**