Created
June 25, 2021 08:20
-
-
Save yohhoy/5f104e6d3aee2b3e927419664abf63af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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