Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Created June 25, 2021 08:20
Show Gist options
  • Save yohhoy/5f104e6d3aee2b3e927419664abf63af to your computer and use it in GitHub Desktop.
Save yohhoy/5f104e6d3aee2b3e927419664abf63af to your computer and use it in GitHub Desktop.
#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