3 ms·
string_view is about expressiveness and design flexibility (vector<char> and char* can trivially convert) that safety. That being said, string_view is arguably
by humanrebar 8y ago
string_view is about expressiveness and design flexibility (vector<char> and char* can trivially convert) that safety.
That being said, string_view is arguably safer than passing around a char* and a length.
- ndesaulniers 8y agohttps://bugs.llvm.org/show_bug.cgi?id=34729 https://bugs.llvm.org/show_bug.cgi?id=34729 Literally had to write a psuedo borrow checker to stop it: https://youtu.be/80BZxujhY38?t=1095 https://youtu.be/80BZxujhY38?t=1095 So much work rather than admit the interface is bad and you should feel bad. C++: "shoot yourself in the ~~foot~~ face."
- rwbt 8y agoSooner or later, C++ is going to get a borrow checker anyways. I guess it's all going to be ok? :) I'm not entirely sold on string_view or span yet. But I wasn't sold on tuples either and I use them a lot now.
- deleted 8y ago[deleted]
- humanrebar 8y agoThe bug there is implicitly converting an r-value to a non owning reference. We wouldn't call the same semantics a bug with a 'char const*' to be fair. We would complain that string implicitly converts or reject the application code as buggy. That being said, yes, string semantics are hard. Passing around copies of a string buffer (std::string) or calling to_string_view everywhere don't seem better.