Created
March 5, 2022 15:29
-
-
Save XuhuaHuang/072149f2ceff9ea4ddd58d0e9526216f to your computer and use it in GitHub Desktop.
String trim operation with C++20 views.
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
inline constexpr auto trim_front = views::drop_while(::isspace); | |
inline constexpr auto trim_back = views::reverse | |
| views::drop_while(::isspace) | |
| views::reverse; | |
inline constexpr auto trim = trim_front | trim_back; | |
std::string trim_str(const std::string& str) { | |
return str | trim | rangesnext::to<std::string>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment