-
Notifications
You must be signed in to change notification settings - Fork 93
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
Make boost::json::string implicitly convertible to std::string #584
Comments
There would be significant harmful consequences for users of the library if we adopt these changes.
This is by design. Construction of
If
This code will compile and work, but there is now an expensive, unnecessary copy taking place which might not be what the user intended. The caller can opt-in to the conversion by using
A better solution is to change the function
Using
We can't get rid of
If you want to be able to switch without changing your code, then you can create your own type aliases and use them in your program:
We could have done this, but then users of Boost.Asio and C++17 would be using two different error codes, as Asio always uses Note that Boost.JSON is really two completely separate libraries in terms of symbols. The standalone JSON linker names are different from the Boost JSON linker names. See: json/include/boost/json/detail/config.hpp Line 141 in 351603c
This is not really a good choice due to performance considerations (construction of |
Ok thanks for the good explanations! I'll close this issue for now. In my use case I have to use the serialized string value (or even the json string values) to build other custom types, which eventually will require the "expensive conversion". I will have to see if there's a way to avoid these w/o exposing too much the underlying json boost types. |
BTW...it might be worth aliasing |
But we can't do that, because
It already works that way. |
Please open a new issue |
I figured it out. It needs to be within boost::json namespace or the global namespace. If it's within the project's namespace ADL does not work. Should probably be more explicitly stated in the examples online. |
Yeah, although it isn't intended that users are supposed to customize std types. If you open an issue, we can make sure Boost.JSON does it for you. |
Ok, thanks. If you think it's worth adding explicit support for |
Well I think it already works in the develop branch |
I'm not so sure about |
Did we have plans to make it work? I can't remember |
We didn't exactly have plans, but we discussed that it should work. |
Please open a new issue |
Version of Boost
1.75
This is more of a would-be-nice type of issue.
Because the
boost::json::string
is not implicitly convertible tostd::string
you have to always do:Alternatively remove the
boost::json::string
type altogether, unless it has some special built-in features which I'm not aware of.Same goes for
boost::string_view
.I understand that under JSON_STANDALONE these types are aliased to STL types, but from a user perspective is highly undesirable. If I want to switch tomorrow from standalone to boost+json or vice-versa, my code will no longer compile. Ideally consider not using any other boost types unless you have < C++17, in which case you simply use std::string instead of string_view on your public interfaces.
The text was updated successfully, but these errors were encountered: