-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
comparing to 0 literal #414
Comments
Add a function overload for comparing to int, so that the 0 literal is not converted to nullptr.
Add a function overload for comparing to int, so that the 0 literal is not converted to nullptr.
The proposed fix fails to compiles I guess this could be fixed with CompatibleNumberIntegerType, but the constructors are already handling all those cases, including converting a nullptr. Just removing the |
When |
Overloading the comparison operators for nullptr isn't really needed, since the constructor can convert nullptr to a json.
The errors after removing the But clang this is not the only comparison that is failing on clang: |
When comparing json j = false;
bool b = false;
std::cerr << "j == false : " << (j == false) << "\n";
std::cerr << "j == b : " << (j == b) << "\n"; Gives
Not so on gcc 6.2, but maybe others are affected as well. Locally I added an explicit |
@pboettch I can confirm your issue with macOS Sierra's Clang. The code does not compile:
|
Ideally would be a function like template<class CompatibleType, typename std::enable_if<
std::is_constructible<basic_json, CompatibleType>::value, int>::type = 0>
friend bool operator==(CompatibleType lhs, const_reference rhs) noexcept
{
return (basic_json(lhs) == rhs);
} which basically like "comparability" to "constructability". |
Using I updated the pull request to use Note that some of the added tests were previously generating compile errors due to ambiguous overloads, so for example |
Merged with 057b1e6. Thanks everybody! |
Hello,
Comparing to the 0 literal results calls
operator==(const_reference v, std::nullptr_t)
since converting to a standard type is preferred to a custom one (json).The text was updated successfully, but these errors were encountered: