Consider the following snippet:
// included, for exposition only
SomeData buzz(std::string_view);
constexpr auto foo(std::string_view v) {
using namespace std::string_view_literals;
return v
| std::views::split(";"sv)
// `std::string_view` constructor from Range is explicit, so this line is necessary
| std::views::transform([](const auto& s) { return std::string_view(s); })
| std::views::transform(buzz)
;
}
Ideally I'd have only the transformations required by the actual algorithm without working around the language's/Standard Library's limitations:
constexpr auto bar(std::string_view v) {
using namespace std::string_view_literals;
// To be used as a chainable range closure more code is required
constexpr auto split{[](std::string_view v, std::string_view delim){
return v | std::views::split(delim) | std::views::transform([](const auto& v){ return std::string_view(v); });
}};
return split(v, ";"sv)
| std::views::transform(buzz);
}
Does the Standard Library provide a view adaptor that splits a std::string_view into std::string_view elements without the extra transform, or is a custom wrapper unavoidable?
autotransform with thestring_viewtransform? Even if the second transform is a function, you could just call it with the first.std::string_view. Your first transform only exists to satisfy that unnecessary limitation.std::string_viewadds clarity over justconst autosplitis better in this regard