-
Notifications
You must be signed in to change notification settings - Fork 54
Add option to use std::string_view #201
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
base: experimental-record
Are you sure you want to change the base?
Add option to use std::string_view #201
Conversation
A question: There is any substancial advantages? |
There are various reasons you want to use std::string_view for function parameters and especially constexpr constant literals. See https://abseil.io/tips/1 The problem is it's awkward to migrate your existing project to use std::string_view when the libraries you depend on are still using |
Nice. In your tests, the |
The main problem is that Imagine you have a Djinni record which contains a Djinni string. When you pass this record from Java to C++, C++ will receive a record that is only valid within the function scope. If you keep that record beyond the scope of the function, you just created a dangled This is too big a risk for average C++ programmers and could be a surprise for experienced C++ programmers. |
Ok I understand now. This is only changing parameter passing from So what this means is |
downsides i can think of from the top of my head:
|
That's the case with most flag options, right?
Yes, but I think that's fine as long as the new options is not the default. On the other hand,
Most C++ devs didn't realize that the above code will allocate a new string. That's why intentionally,
That's fair. But I think that's just part of the evolution of C++. Use of std::span has the same issue. |
The only case this change affects is when a |
I'm not sure if that should be considered inconsistent. In that case, the parameter is a reference to a record, not a string. Similarly, an int method parameter is passed by value. But an int field in a record is "passed" by reference when the method parameter is a record. In the latter case, the observed value of the int could change if the caller changed the record concurrently. This is just as "inconsistent". |
No description provided.