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
Document when value_from is needed #845
Comments
First of all, yes, this code is correct. Second, I honestly can't see the source of confusion: you need |
For me, I feel that it would make sense for boost::json to implicitly know to convert std::vector to a json array in this case. I just ran into this issue myself, where the implicit conversion was working fine in 1.80, and now I have build errors in 1.81 (I'm going back to 1.80 with the hope that I won't find the desire to use std::variant or std::optional). So that's my source of confusion. |
As, I've mentioned previosuly, the behaviour was never intended. If it was,
I am not aware of any container type that does implicit conversions from other container types. In particular, standard container types definitely do not do that. There is a reason for that: implicit conversions cannot be locally disabled, they are pervasive, they create potential for lots of unintended conversions. They are a particularly terrible idea when memory is likely to be allocated. |
I agree that this is a better design than implicit conversion. My heuristic is if an allocation is probably required then I need value_from and usually pass the storage ptr. |
This could be related. In 1.80 the following used to work but in 1.81 it doesn't compile:
In 1.81 I need to use value_from otherwise it doesn't compile:
Of course, in 1.80 I had my own tag_invoke overload for described enum but it is added in 1.81. It's a pity because the pretty initializer format is not working with 1.81+ for custom types or am I missing something? |
Yes, this behaviour was never intended and wasn't documented and so we removed the code that accidentally allowed it to work. |
Since 1.81 this no longer compiles:
I see from #823 that this is intended. But it is not clear when calling
value_from
is needed and maybe the idiomatic way of doing it should be documented e.g. in the example here https://www.boost.org/doc/libs/1_81_0/libs/json/doc/html/json/quick_look.html. I assume the optimal way to do this now is the followingIs this correct?
The text was updated successfully, but these errors were encountered: