diff --git a/src/json.hpp b/src/json.hpp index ff0ce5add..6f52255bc 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -13025,6 +13025,22 @@ struct hash return h(j.dump()); } }; + +/// specialization for std::less +template <> +struct less<::nlohmann::detail::value_t> +{ + /*! + @brief compare two value_t enum values + @since version 3.0.0 + */ + bool operator()(nlohmann::detail::value_t lhs, + nlohmann::detail::value_t rhs) const noexcept + { + return nlohmann::detail::operator<(lhs, rhs); + } +}; + } // namespace std /*! diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index fc7cf9653..7c2c24bfb 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -12059,6 +12059,22 @@ struct hash return h(j.dump()); } }; + +/// specialization for std::less +template <> +struct less<::nlohmann::detail::value_t> +{ + /*! + @brief compare two value_t enum values + @since version 3.0.0 + */ + bool operator()(nlohmann::detail::value_t lhs, + nlohmann::detail::value_t rhs) const noexcept + { + return nlohmann::detail::operator<(lhs, rhs); + } +}; + } // namespace std /*! diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 7980371bc..f7b560502 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -795,4 +795,11 @@ TEST_CASE("regression tests") std::string s2 = j2.dump(); CHECK(s1 == s2); } + + SECTION("issue #486 - json::value_t can't be a map's key type in VC++ 2015") + { + // the code below must compile with MSVC + std::map jsonTypes ; + jsonTypes[json::value_t::array] = "array"; + } }