Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
#include <ranges>
int main() {
std::string_view str = "apple,banana,cinnamon";
for (auto rev_item: str | std::views::reverse | std::views::split(',')) {
static_assert( std::ranges::forward_range<decltype(rev_item)>);
static_assert(!std::ranges::bidirectional_range<decltype(rev_item)>); // pre-P2210R2
auto cv = rev_item | std::views::common;
std::string tmp{cv.begin(), cv.end()};
std::reverse(tmp.begin(), tmp.end());
std::cout << tmp << '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment