C++ Logo

std-proposals

Advanced search

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

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Fri, 11 Jul 2025 06:42:10 +0200
> On Jul 10, 2025, at 7:11 PM, Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Thu, Jul 10, 2025 at 12:05 PM Sebastian Wittmeier via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> Is it really so far-fetched?
>
> Well, your specific example was just terrible from a UX perspective.
> Using code to create invisible identifiers that you have to read
> generative metaprogramming code to know what the API actually is is
> not a good idea if you want users to know what's going on. Converting
> CamelCase to lower_case is such a trivial thing that using generative
> metaprogramming to do it makes the code harder to work with, not
> easier.

Well, let’s make an example that (at least to me) seems more plausible:

enum class Cities
{
  LONDON,
  NEW_YORK,
  RIO_DE_JANEIRO,
}

Maybe it’s not cities, but something else. One of the reflections examples is how to get the strings names of the enum values. However, it would be nicer if the cities were written with the correct capitalization. There is no perfect rule to get from all caps to the proper city names. But, we might start with the city names instead and (in the future) use them to create the above enum using reflection.
constexpr u8char_t *city_names[] = { “London”, “New York”, “Rio de Janeiro” };
>
> It should also be noted that `constexpr` Unicode processing is not
> *free*. Those tables are not tiny and compile-time code is not nearly
> as fast as runtime code. Running through those tables is not going to
> be quick, especially for more complex operations like Unicode
> normalization.
But, it would also be the zero overhead principle: You don’t pay for what you don’t use. And using these tables at compile time doesn’t even have to include them in the final compiled code. If you need them at runtime, you need them at runtime. There is not much you can do about that. In many cases you only need ASCII. So, there should be functions for ASCII-only and for Unicode.

There might also be the ability to compress these tables. Some smart people will most likely figure this out.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-07-11 04:42:25