You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add support for std::string_view to Json::Value::operator[] #1352
Is your feature request related to a problem? Please describe.
We use std::string_view for names of object entries. However, when accessing values with Json::Value::operator[], we always have to convert the name a std::string first. This incurs an unnecessary allocation and adds boilerplate code.
Describe the solution you'd like
I would like Json::Value::operator[] to support std::string_view.
Describe alternatives you've considered
As mentioned an alternative is to convert the name to std::string first, but this is less readable and slower. Converting to const char* is in general not possible, because the contents of std::string_view might not be null-terminated.
Additional context
This feature requires C++17. jsoncpp seems to build fine with C++17 so this shouldn't be a problem as long as the feature is deactivated when compiling with a lower standard. #999 already implemented this feature, but was closed. It is not clear to me why the PR was closed. If there is additional work necessary, I am happy to help.
The PR was incorrect code.
I don't think it would compile. A key variable was misspelled.
It could create an ambiguity among the overloads of the operator[], which would break some users.
the detection of C++17 was incorrect for the case where jsoncpp is built without c++17 but the client code is built with it. The client would have missing symbol errors.
There are workarounds for these problems but it is not simple.
Activity
BillyDonahue commentedon Nov 5, 2021
The PR was incorrect code.
I don't think it would compile. A key variable was misspelled.
It could create an ambiguity among the overloads of the operator[], which would break some users.
the detection of C++17 was incorrect for the case where jsoncpp is built without c++17 but the client code is built with it. The client would have missing symbol errors.
There are workarounds for these problems but it is not simple.
aberaud commentedon Mar 24, 2022
GCC is now moving to C++17 by default, and C++20/22 include additional support for
std::string_view.This feature would be great to improve performance and code readability!
Also simply to be compatible and interoperable with the C++ standard library...
aberaud commentedon Mar 28, 2022
first step here: #1397
bcsgh commentedon Dec 4, 2024
Any chance of reviving this?
And while this is being done adding the corresponding constructor
Json::Value::Value(std::string_view)would be nice.