Re:Learn Modern C++
by erik_seaberg on Wednesday December 27, 2023 @07:02PM
(#38788406)
I don’t have a modern implementation handy, but according to https://en.cppreference.com/w/cpp/string/basic_string_view/d... a string_view depends on its data() pointer, and the lifetime of that buffer doesn’t seem to be guaranteed by anything.
Re:Learn Modern C++
by angiosperm on Thursday December 28, 2023 @01:16AM
(#38790622)
Thus, the word "view". It refers to storage being managed by the creator of the string_view object, in this case a file mapped using mmap and not unmapped until after program termination.
Re:Learn Modern C++
by protomolecule on Thursday December 28, 2023 @12:11PM
(#38795646)
"so cannot have bugs caused by misusing the pointers"
std::string_view lets you have some of the bugs that are caused by misusing pointers.
Try: "g++ -std=c++20 lb.cc && ./a.out iodhuamplrnc words".