I have a match table with start and end indices of portions, in array (in a callback) - I wrap that array into vector of strings - now recently I did have the need to modify the original portions of the string.
struct regexcontext {
std::vector<std::optional<std::string>> matches;
std::string subject;
};
int buildmatchvector(size_t(*offset_vector)[2], int max, regexcontext* pcontext) {
pcontext->matches.clear();
ranges::transform(ranges::span{ offset_vector, max }, std::back_inserter(pcontext->matches), [&](const auto& refarr) {
return refarr[0] == -1 ? std::optional<std::string> {} : std::optional<std::string>{ pcontext->subject.substr(refarr[0], refarr[1] - refarr[0]) };
});
return 0;
}
Is it possible to change the above definition in a way that by modifying the match vector I will modify the subject string as well.
I've heard of string view but I've also heard it can't be modified with a variable sized string.
Note I'm using ranges-v3
which is the only library that implements standard ranges at the moment plus the nonstandard ranges::span
which allows me to compile on msvc (since std::span
doesn't work there for some reason).