From 21dcd4bd3961978de6d1a491244b88d222c609cc Mon Sep 17 00:00:00 2001 From: Pratik Chowdhury Date: Sun, 9 Dec 2018 16:34:38 +0530 Subject: [PATCH 1/2] Fixes https://github.com/nlohmann/json/issues/1387 In https://github.com/nlohmann/json/issues/1387, a user was facing difficulty because he was using map class. Map class sorts it's elements on the basis of < function. Now this meant that the bug existed in inline bool operator< If you are to look at the Numerics Mentioned beside the comment in the previous code base, you would find that they do not match the one mentioned/implied in enum class value_t The correction of these values fixes the issue altogether --- include/nlohmann/detail/value_t.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/value_t.hpp b/include/nlohmann/detail/value_t.hpp index 10d555b997..873fdc3ca7 100644 --- a/include/nlohmann/detail/value_t.hpp +++ b/include/nlohmann/detail/value_t.hpp @@ -63,8 +63,8 @@ Returns an ordering that is similar to Python: inline bool operator<(const value_t lhs, const value_t rhs) noexcept { static constexpr std::array order = {{ - 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, - 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */ + 0 /* null */, 1 /* object */, 2 /* array */, 3 /* string */, + 4 /* boolean */, 5 /* integer */, 6 /* unsigned */, 7 /* float */ } }; From f804030d078d01f770835d4fe74ec7101efb4536 Mon Sep 17 00:00:00 2001 From: Pratik Chowdhury Date: Sun, 9 Dec 2018 17:24:40 +0530 Subject: [PATCH 2/2] Files amalgamated --- .gitignore | 1 + single_include/nlohmann/json.hpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 35dc9b42ce..086e855c05 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ benchmarks/files/numbers/*.json cmake-build-debug test/test-* +/.vs diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 016ba39d7b..8c01a18547 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -1181,9 +1181,9 @@ Returns an ordering that is similar to Python: */ inline bool operator<(const value_t lhs, const value_t rhs) noexcept { - static constexpr std::array order = {{ - 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, - 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */ + static constexpr std::array order = { { + 0 /* null */, 1 /* object */, 2 /* array */, 3 /* string */, + 4 /* boolean */, 5 /* integer */, 6 /* unsigned */, 7 /* float */ } };