C++11 Trim Functions
For C++11 #include <algorithm> #include <cctype> #include <locale> // Trim from the start (in place) inline void ltrim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), return !std::isspace(ch); })); } // Trim from the end (in place) inline void rtrim(std::string &s) { s.erase(std::find_if(s.begin(), s.rend(), [](unsign return !std::isspace(ch); }).base(), s.end()); } Thanks to std::ptr_fun replacement for C++17 for bringing up the modern solution.
A programming post shows verbose C++11 functions for trimming whitespace from the beginning and end of a string. The joke is that an old, cumbersome C++11 solution is presented as the “modern solution,” while the caption points out that a C++17 replacement for std::ptr_fun is responsible for it. It is used as a reaction to the complexity and awkward evolution of C++ standards. EN: A programming post shows verbose C++11 functions for trimming whitespace from the beginning and end of a string. The joke is that an old, cumbersome C++11 solution is presented as the “modern solution,” while the caption points out that a C++17 replacement for std::ptr_fun is responsible for it. It is used as a reaction to the complexity and awkward evolution of C++ standards.
- @gentoomemes / 17835 2025-07-07
- Type
- image
- Size
- 800×675 · 68.9 KiB
- Mood
- sarcastic, absurd
- Language
- en
- Added