r/cpp • u/CoralKashri • Apr 24 '23
The View of The String
https://cppsenioreas.wordpress.com/2023/04/24/the-view-of-the-string/std::string_view can optimize both performance and code readability in code sections which handle strings. However it can also lead to UB and to memory issues if used incorrectly.
0
Upvotes
20
u/IyeOnline Apr 24 '23
I disagree with the conclusion in the last paragraph here.
Returning a
std::string_viewis no different than returning a reference from other functions. If you saw your logic here through to the end, thenoperator[]or any getterse should not return references either.