I've split my string into vector<string_view> and now I'd like to get back the original string (or a list of substrings if elements were deleted). my question is, does string_view::substr allow for increasing size according to the standard? any suggestions for using algorithms or ranges/view in smoothen()? (I'm aware splitting could be done with split_view too.) how about using a view_interface instead of vector, would I still be able to distinguish the individual words after join_view, or would it just become a complicated kind of string?
here's my test-code:
does string_view::substr allow for increasing size according to the standard?
I'm not sure I'm understanding what is meant by this.
std::string_view is a read-only view referencing the underlying data. You can have multiple views of the same underlying data - but you can't change the underlying data via string_view. Neither can you concatenate etc data to a string_view.
all that is nifty and stuff, but the actual problem can be solved by
... whatever, get data into s1
... code to mess up s1
s2 is still the original string.
if you deleted something, you can either apply the same to s2 (if possible, and it should be) or you end up back trying to do the above complexity (seems best to avoid, in this specific use case?)
It seems to me that OP's problem would be better solved with just the original string and a vector of offsets/pointers into it. The point of a string_view is to be a read-only slice of an object. If you're talking about shifting or splicing a string_view, it's probably not what you want. The code that uses the string_view should not assume that there's any more memory to extend into.
thanks, that's exactly the clearheadedness I were looking for. hope you're aware that when giving split() the parameter "false" then the same can be achieved by c++20 stl functions in more readable way.
as for explanation of what I'm trying to achieve: I discovered the library "dtl" which creates a diff between 2 vectors. so when I feed it vectors of string_view where each element contains either a whole word (or maybe alphanumeric sequence) or a single character, it would tell me at which characters or words the two strings differ, just like some fancy diff-visualizer widgets do. so I can program a widget to visualize the differences with colours or further analyze why the words differ (when analyzing plagiarism or spam). all I have to do is to smoothen the output whenever it's continuous, to save on space...