From f77dfdb0686c29c54be841580e6b406736a61bdf Mon Sep 17 00:00:00 2001 From: Patrick Boettcher Date: Sat, 24 Dec 2016 00:08:23 +0100 Subject: [PATCH] validation: use set-return-value to see whether an element has been inserted or not --- src/json-schema-validator.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/json-schema-validator.hpp b/src/json-schema-validator.hpp index a27ac4a..d15a11e 100644 --- a/src/json-schema-validator.hpp +++ b/src/json-schema-validator.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include // make yourself a home - welcome to nlohmann's namespace namespace nlohmann @@ -198,9 +198,13 @@ class json_validator const auto &uniqueItems = schema.find("uniqueItems"); if (uniqueItems != schema.end()) if (uniqueItems.value() == true) { - std::unordered_set array_to_set; + std::set array_to_set; for (auto v : instance) { - array_to_set.insert(v); + auto ret = array_to_set.insert(v); + if (ret.second == false) + throw std::out_of_range(name + " should have only unique items."); + } + } } if (instance.size() != array_to_set.size())