Date: Thu, 3 Jul 2025 09:50:23 +0100
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?
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?
Received on 2025-07-03 08:50:32