Since is_palindrome()
accepts ranges of any equality-comparable type, palindrome_view
doesn't need to be a range of char
, and there's need to cast within the transform()
:
auto constexpr palindrome_view =
std::views::filter([](unsigned char c){ return std::isalnum(c); }) |
std::views::transform([](unsigned char c){ return std::toupper(c); });
In case it's not clear, thisThis view iswasn't part of the testsmain code because it's not generic. It would But it could be easymade to create a wide-char version, using std::iswalnum()
andwork for other character types by including std::towupper()<locale>
frominstead of <cwctype><cctype>
, but a fully generic version isn't possible using only the standard library.:
auto palindrome_locale = std::locale::classic();
auto constexpr palindrome_view =
std::views::filter([](auto c){ return std::isalnum(c, palindrome_locale); }) |
std::views::transform([](auto c){ return std::toupper(c, palindrome_locale); });