C++ Logo

std-proposals

Advanced search

Re: [std-proposals] constexpr tolower, toupper, isalpha

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 3 Jul 2025 09:52:32 +0100
On Thu, 3 Jul 2025 at 09:50, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Rather than have to write functions like:
>
> inline constexpr char tolower_consteval_char(char const c) noexcept
> {
> switch ( c )
> {
> case 'A': return 'a'; case 'B': return 'b'; case 'C':
> return 'c'; case 'D': return 'd';
> case 'E': return 'e'; case 'F': return 'f'; case 'G':
> return 'g'; case 'H': return 'h';
> case 'I': return 'i'; case 'J': return 'j'; case 'K':
> return 'k'; case 'L': return 'l';
> case 'M': return 'm'; case 'N': return 'n'; case 'O':
> return 'o'; case 'P': return 'p';
> case 'Q': return 'q'; case 'R': return 'r'; case 'S':
> return 's'; case 'T': return 't';
> case 'U': return 'u'; case 'V': return 'v'; case 'W':
> return 'w'; case 'X': return 'x';
> case 'Y': return 'y'; case 'Z': return 'z';
> }
>
> return c;
> }
>
> Granted I didn't have to write that out myself because ChatGPT did it
> for me, but can we make the likes of std::tolower, std::toupper,
> std::isalpha, and so on, all constexpr?
>

They depend on the current locale.

Received on 2025-07-03 08:52:47