-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json::value_t can't be a map's key type in VC++ 2015 #486
Comments
Can you please provide the error messages from MSVC? |
No problem. Here:
|
Could you try explicitly to pass |
I don't know how to pass the operator itself, but I tried passing a functor, like this:
And the result was this:
Then I tried using
This seems to be an argument-dependent lookup issue. For some reason the compiler is not prioritizing Hopefully there is a way to solve it, so we don't need this workaround. |
This seems to be an issue where @theodelrieu may know more. |
I will take a look tomorrow, this looks like a MSVC-specific weirdness at first sight |
There is a workaround mentioned in this StackOverflow thread namespace std {
template <>
struct less<::nlohmann::detail::value_t>
{
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
{
return ::nlohmann::detail::operator<(lhs, rhs);
}
};
} |
Is it safe to add this to the |
That's a template specialization, it's allowed and safe. Plus, this is what the default |
MSVC needs this overload to compile code containing a std::map that uses nlohmann::detail::operator as key.
The following code now compiles with MSVC 2015 (see https://ci.appveyor.com/project/nlohmann/json/build/1765): std::map<json::value_t, std::string> jsonTypes ;
jsonTypes[json::value_t::array] = "array"; @Getfree Can you try this version of the code please: f4126e4 |
I added the fixed version to my project and it compiled successfully. Many thanks. |
The following code does not compile in Visual Studio 2015, but compiles fine in GCC.
Wandbox: http://melpon.org/wandbox/permlink/Izdt8DW4UGpVQdUd
The text was updated successfully, but these errors were encountered: