🚑 fix for #486

Implemented std::less<value_t> to allow using value_t as std::map key
in MSVC.
pull/508/head
Niels Lohmann 2017-03-12 10:40:36 +01:00
commit 4d7c29923e
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 39 additions and 0 deletions

View File

@ -13048,6 +13048,22 @@ struct hash<nlohmann::json>
return h(j.dump());
}
};
/// specialization for std::less<value_t>
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
/*!

View File

@ -12082,6 +12082,22 @@ struct hash<nlohmann::json>
return h(j.dump());
}
};
/// specialization for std::less<value_t>
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
/*!

View File

@ -796,6 +796,13 @@ TEST_CASE("regression tests")
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<json::value_t, std::string> jsonTypes ;
jsonTypes[json::value_t::array] = "array";
}
SECTION("issue #494 - conversion from vector<bool> to json fails to build")
{
std::vector<bool> boolVector = {false, true, false, false};