-
-
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
converting json to vector of type with templated constructor #924
Comments
I'm looking at this. Adding Please note that you're exposing yourself to HUGE problems with a non-explicit templated constructor, without any constraints ( This library is confronted to this issue, since Here is an example with your type // innocent-looking operator==
bool operator==(S, S) { return true; }
// innocent type
struct Innocent {};
Innocent t;
// Compiles... and call operator==(S, S)
t == t; |
The culprit is indeed the Here is the output:
This ambiguity is what prevent your code from working, Thanks for the report! EDIT: It'll take a bit more time, there is more stuff to fix than what I thought |
Thanks. The actual type is from a library so I can't change the constructor.
I'm not sure is_constructible is appropriate here. I think you just need to
check that get<T>() is valid.
…On 19 Jan 2018 12:09 pm, "Théo DELRIEU" ***@***.***> wrote:
The culprit is indeed the is_convertible check, I added the following
method (following this cppreference
<http://en.cppreference.com/w/cpp/types/is_convertible> page)
Here is the output:
t.cpp:14:19: error: conversion from 'nlohmann::basic_json<std::map,
std::vector, std::__1::basic_string, bool, long long, unsigned long long,
double, std::allocator,
adl_serializer>' to 'S' is ambiguous
T test() { return std::declval(); }
^~~~~~~~~~~~~~~~~
t.cpp:24:3: note: in instantiation of function template specialization
'test<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string,
bool, long long,
unsigned long long, double, std::allocator, adl_serializer>, S>' requested
here
test<nl::json, S>();
^
develop/json.hpp:3053:5: note: candidate function [with ValueType = S, $1
= 0]
operator ValueType() const
^
t.cpp:7:25: note: candidate constructor [with T =
nlohmann::basic_json<std::map, std::vector, std::__1::basic_string, bool,
long long, unsigned long long, double,
std::allocator, adl_serializer>]
template S(const T &t) {}
This ambiguity is what prevent your code from working, I will open a PR to
replace the is_convertible to is_constructible.
Thanks for the report!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#924 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHTojR_ePuofeCR6m7uAB3ejqCjb8C74ks5tMGnSgaJpZM4Rjs5L>
.
|
Yeah I was wrong, I realized that all those constraints made no sense whatsoever, I shall fix them when I have some free time. Meanwhile, I would suggest you completely remove the line with the Also, if you cannot change the code of the library you use, I would suggest to open an issue :) |
Any news on this? |
I had no time to work on it yet, it is linked with another issue I've found which I will open as soon as I can. |
Ok, no worries. |
@theodelrieu Any idea on how to proceed with this issue? |
IIRC this was related to #958, I'll check tomorrow the compiler errors to be sure. |
With PR #969 and the code in #924 (comment) compiles without issues. |
Thanks!
On 12 Feb 2018 7:18 pm, "Niels Lohmann" <notifications@github.com> wrote:
Closed #924 <#924> via #969
<#969>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#924 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AHTojc8JqE6T1YAyM2JSuyrV1v3ls0Dxks5tUHJTgaJpZM4Rjs5L>
.
|
Bug Report
The following code fails to compile when uncommenting line 16:
The error I get is
The cause seems to stem from the check for
std::is_convertible<BasicJsonType, typename CompatibleArrayType::value_type>::value
onvoid from_json(const BasicJsonType& j, CompatibleArrayType& arr)
.Since you do not convert directly from json to the array value but call
get()
I think this check can be changed to allow this to compile.Compiled on VS 15.6.0 preview 2.0
Library version 3.0.1
The text was updated successfully, but these errors were encountered: