Код: Выделить всё
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([](std::string_view v) {
// Some further logic here
return v;
})
;
}
Код: Выделить всё
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([](std::string_view v) { return v; });
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... viewssplit
Мобильная версия