|
|
|
|
|
by ropejumper
555 days ago
|
|
Two people have already mentioned things like storing the length inline or including a null-terminator to be backwards-compatible. What's described there is basically the same as std::string_view or &str, and to me one of the biggest reasons to use these structures is that your particular view of the string doesn't interfere with someone else's. You can slice your string in the middle and just look at it piecewise without bothering anyone else. Choosing between these trade-offs just depends on what you're doing. I'd definitely choose this pattern if I were to write a parser for instance. |
|