The Problem with C++ Safety: Modern C++ Is a Mindset, Not a Standard
cppdashboard.dev/r/2026/11/the-problem-with-cpp-safety-modern-cpp-is-a-mindset-not-a-stIn the first part of this article, we have taken a look at two attempts to decide whether a given string is a palindrome. Both implementations were written in “Classic C++” and didn’t feel great: the code was difficult to read, hard to…
From the article
In the first part of this article, we have taken a look at two attempts to decide whether a given string is a palindrome. Both implementations were written in “Classic C++” and didn’t feel great: the code was difficult to read, hard to understand and consequently the defects were difficult to detect. Now it’s time to continue the story and to take a look at a better solution, the “Modern C++” solution.
So let’s take a look at a modern C++ solution.
[[nodiscard]] bool is_palindrome( std :: string_view str ) { return std :: equal( str.cbegin(), str.cbegin() + str.size() / 2U , str.crbegin() ); } Yes, it’s that simple: a single function call to the std::equal() algorithm. We compare the first half of the range represented by forward iterators with the second half of the range represented…
Share this resource