diff --git a/src/json.hpp b/src/json.hpp index a9685158..c2542682 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -8902,7 +8902,13 @@ basic_json_parser_63: : callback(cb), m_lexer(reinterpret_cast(&(*first)), static_cast(std::distance(first, last))) - {} + { + int i = 0; + assert(std::accumulate(first, last, true, [&i, &first](bool res, decltype(*first) val) + { + return res and (val == *(std::next(std::addressof(*first), i++))); + })); + } /// public parser interface basic_json parse() diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 82b6a123..20eb6e58 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -8199,7 +8199,13 @@ class basic_json : callback(cb), m_lexer(reinterpret_cast(&(*first)), static_cast(std::distance(first, last))) - {} + { + int i = 0; + assert(std::accumulate(first, last, true, [&i, &first](bool res, decltype(*first) val) + { + return res and (val == *(std::next(std::addressof(*first), i++))); + })); + } /// public parser interface basic_json parse() diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index 863cec52..b6d6a615 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -750,42 +750,42 @@ TEST_CASE("parser class") SECTION("from std::vector") { std::vector v = {'t', 'r', 'u', 'e', '\0'}; - CHECK (json::parser(std::begin(v), std::end(v)).parse() == json(true)); + CHECK(json::parser(std::begin(v), std::end(v)).parse() == json(true)); } SECTION("from std::array") { std::array v { {'t', 'r', 'u', 'e', '\0'} }; - CHECK (json::parser(std::begin(v), std::end(v)).parse() == json(true)); + CHECK(json::parser(std::begin(v), std::end(v)).parse() == json(true)); } SECTION("from array") { uint8_t v[] = {'t', 'r', 'u', 'e'}; - CHECK (json::parser(std::begin(v), std::end(v)).parse() == json(true)); + CHECK(json::parser(std::begin(v), std::end(v)).parse() == json(true)); } SECTION("from char literal") { - CHECK (json::parser("true").parse() == json(true)); + CHECK(json::parser("true").parse() == json(true)); } SECTION("from std::string") { std::string v = {'t', 'r', 'u', 'e'}; - CHECK (json::parser(std::begin(v), std::end(v)).parse() == json(true)); + CHECK(json::parser(std::begin(v), std::end(v)).parse() == json(true)); } SECTION("from std::initializer_list") { std::initializer_list v = {'t', 'r', 'u', 'e', '\0'}; - CHECK (json::parser(std::begin(v), std::end(v)).parse() == json(true)); + CHECK(json::parser(std::begin(v), std::end(v)).parse() == json(true)); } SECTION("from std::valarray") { std::valarray v = {'t', 'r', 'u', 'e', '\0'}; - CHECK (json::parser(std::begin(v), std::end(v)).parse() == json(true)); + CHECK(json::parser(std::begin(v), std::end(v)).parse() == json(true)); } } }