3 ms·
1. In the introduction, Herb Sutter mentions this talk is also for people that might not know about C++11 features. 2. Use std::string for when you need to own
by humanrebar 8y ago
1. In the introduction, Herb Sutter mentions this talk is also for people that might not know about C++11 features.
2. Use std::string for when you need to own a string. Use std::string_view when you need to reference a string [a]. Generally you want std::string_view for parameters and std::string for member variables. Return values and local variables can be either, but if you're not sure, std::string is safer though slower.
3. You chain optional, but only with nested functions, and you code starts looking more and more like lisp. If you are a fan of a chained syntax, you might be interested in libraries that support "ranges". boost already has ranges and there are proposals to add them to C++20.
[a] If you want more specifics and detail, the CppCoreGuidelines have a section on when to use which string.
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#slstr-string https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...
- saagarjha 8y agoTIL about std::byte; I should have probably used it instead of char in a recent project of mine…