Compiling this as C++20 or C++latest? I remember VS 2022 (and 2019) had problems with a handful C++20 features such as ranges as C++20 until recent updates.
template<typename T = std::string_view>
auto split(const std::string_view str, const std::string_view delims = ",") {
std::vector<T> output;
for (constauto& s : str | std::views::split(delims)) {
auto word {s | std::views::drop_while(isspace) | std::views::reverse | std::views::drop_while(isspace) | std::views::reverse};
auto cv { word | std::views::common };
//output.emplace_back(cv.begin(), cv.end());
output.emplace_back(std::to_address(word.begin()), std::to_address(word.end()));
}
return output;
}
L7 compiles - but why using std::views when the std::ranges version doesn't???
However L9 doesn't compile - with a load of standard library errors. The first being "xmemory(678,18): error C2672: 'std::construct_at': no matching overloaded function found"
The reason you needed those ghastly to_address calls is that reverse/drop_while/reverse chain of range view adaptors lost contiguousness; it produced a random_access range. A plain split would produce contiguous range and you'd be able to just use string_view(w.begin(), w.end()) as on https://en.cppreference.com/w/cpp/ranges/split_view#Example
I think a more range-y thing is to use ranges::to (now part of C++23, but I'll use range-v3 so it can work)
Even more rangey is to just keep working with a range until you have to iterate it, never stuffing it into a container until you must (here, quoted's argument is where something must be done since it doesn't take range views;
or you could implement quoted on range views.. or indeed, do that that s.begin(), s.end() construction, at this point, with to_address to account for lost contiguousness (I wonder if v3's split_when has a bug, there's no reason it should downgrade to random-access)