-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add cxx17 string_view operator[] for Json::Value #999
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
Conversation
include/json/config.h
Outdated
@@ -12,6 +12,7 @@ | |||
#include <ostream> | |||
#include <sstream> | |||
#include <string> | |||
#include <string_view> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the system doesn't support C++17 Standard now, so it cannot open include file string_view
but if you like, you could use the __plusplus marco switch :
#if __cplusplus >= 201703L
#include <string_view>
#endif
@@ -141,6 +142,7 @@ using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY, | |||
SecureAllocator<T>, | |||
std::allocator<T>>::type; | |||
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>; | |||
using StringView = std::basic_string_view<char, std::char_traits<char>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only when the __cplusplus >= 201703L, can this semantics work.
We would have to include abseil or move to C++17 for this, so I'm voting to close for now. |
Why? It is just StringView. There are many cases where we can use it. What difference between const string ref and StringView? |
string_view can avoid unnecessary memory allocation. but it only applied in the new c++17 standard and abseil lib. |
What about people who use current master with c++17 standart? For them it is new standart and std::string_view can be applied because it contains pointer and size. Where the problem is?
Thank you |
Maybe it is possible to add as default disabled feature? |
I guess baylesj temporarily closed this PR because we haven't decided to use abseil C++ library or C++17 Standard library. |
supporting std::string_view as a value key should be doable but it would have to be carefully controlled by a #if and we'd have to carefully control the overload set to avoid ambiguities with other string-like types we're using. I don't think abseil has much to do with the decision though, unless I'm missing something. |
As more projects move to C++17, I believe this becomes increasingly necessary. Additionally to the proposals in this PR, it would be great to have
To be able to read a string Json value without unneeded allocations + copies. |
GCC is now moving to C++17 by default, and C++20/22 include additional support for Other libraries like asio have included support for Could we please list issues with the current patch so they could be solved, so this could move forward and get merged? |
Is it possible to add string_view?
How can we turn it off on older c++ versions?
Can it be another define "JSON_USE_CXX17"? Or compiler defines?
Thank you