Add option to use std::string_view#201
Add option to use std::string_view#201techleeksnap wants to merge 1 commit intoSnapchat:experimental-recordfrom
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.