Date: Fri, 27 Nov 2026 17:03:31 -0600
Thanks for the quick update, Eddie.
Also, thanks for including Alternative 1. I find the name utf_to_utfN
slightly misleading. It seems to imply that it transcodes from one
UTF to another -- which it does -- but it also turns arbitrary garbage
input into nice, shiny UTF-N (with the understanding that the result
may be almost entirely replacement characters). I think the status
quo names are better, especially for naive users.
I would like to change the interpretation of the UTF format of wchar_t
from "based on width" to "implementation defined". Each
implementation knows whether a wchar_t means UTF-16 or UTF-32,
regardless of its width. Not sure if that's a friendly amendment.
I'd also like to see more about the generic case. If I use as_utf32
that recognizes all character types in generic code, as_utf32 is all I
have to write:
// process the code points in the char range R
template<typename R>
auto process_code_points_1(R && r) {
auto cps = r | std::as_utf32;
// do processing here
}
This is incredibly useful, and I use it all over the place in
Boost.Parser. If I have to mention as_charN_t, though:
template<typename R>
auto make_code_points(R && r) {
using char_t = std::ranges::range_value_t<R>;
// The its_charN_ish logic is surprisingly hard to get right
portably, btw (see the paper).
// If I get one of them wrong, I'm advertising UTF-N as UTF-M for
some case below,
// resulting in mojibake that I wouldn't have gotten if the
implementation determines
// which character types correspond to which UTF formats.
if constexpr (its_char8_ish<>)
return r | std::as_char8_t | std::as_utf32;
else if constexpr (its_char16_ish<char_t>)
return r | std::as_char16_t | std::as_utf32;
else if constexpr (its_char32_ish<char_t>)
return r | std::as_char32_t | std::as_utf32;
else
static_assert(!"oopsie");
}
template<typename R>
auto process_code_points_2(R && r) {
auto cps = make_code_points((R &&)r);
// do processing here
}
The punchline? If I write make_code_points() correctly, I get the
same machine code for process_code_points_2() that I would have gotten
for process_code_points_1(). I'm happy to add something like this to
the paper if you like.
Could you explain the rationale for the CHAR_BIT == 8 mandate? Are
people putting UTF-16 or UTF-32 in chars when CHAR_BIT is larger?
Does it matter if they do? We assume that the input is UTF-8 if we're
given char or char8_t input; why should the size of the char matter?
Zach
On Fri, Nov 27, 2026 at 1:15 PM Eddie Nolan <eddiejnolan_at_[hidden]> wrote:
>
> I've written a draft of a paper (D4460R0) that recommends an option aligned with Jonathan's utf_to_utf32 suggestion:
>
> https://docs.google.com/document/d/1S7YuROrepDKqE9HaWMQtl4pMG_zTgelKC6yQ6YhUXWg/edit?usp=sharing
>
> Please take a look and add any suggestions or corrections in a Google Docs comment; or if anyone wants to update the document directly, just request edit access and I'll add you as a coauthor.
>
> One change I made to Jonathan's idea was that, originally, Jonathan suggested that utf_to_utf32 would "dispatch to the appropriate `std::views::as_charXX_t`, followed by `std::views::to_utf32`", but my recommendation instead renames std::views::to_utf32 to std::views::utf_to_utf32 and adds support for char and wchar_t in the view instead of adding an as_char8_t layer. This has the advantages of not increasing the number of range adaptors, and not having .base() give out a transform_view iterator after having written std::string(...) | std::views::utf_to_utf32.
>
> I also added the CHAR_BIT==8 Mandates suggested by Tom Honermann.
>
> Thanks,
>
> Eddie
>
>
> On Sat, Nov 21, 2026 at 7:20 AM Jonathan Wakely <cxx_at_[hidden]> wrote:
>>
>>
>>
>> On Sat, 21 Nov 2026, 10:21 Oliver Hunt via Lib-Ext, <lib-ext_at_[hidden]> wrote:
>>>
>>>
>>>
>>> On Nov 21, 2026, at 1:25 AM, Corentin via Lib-Ext <lib-ext_at_[hidden]> wrote:
>>>
>>>
>>>
>>> On Fri, Nov 20, 2026, 17:16 Eddie Nolan via Lib-Ext <lib-ext_at_[hidden]> wrote:
>>>>
>>>> My thinking was that we would expand the scope of the transcoding range adaptors to interpret char as UTF-8 and wchar_t as UTF-16 or UTF-32 depending on width, and if you want to use any other type you still need to use the casting range adaptors (which we would keep).
>>>>
>>>> I hadn’t thought about the CHAR_BIT thing but the Mandates seems like the right thing to do there.
>>>
>>>
>>> Yup, no point in supporting theorical platforms or invent things not covered by the Unicode standard.
>>>
>>>
>>> One _possible_ concern with interpreting wchar_t as being utf16 rather than ucs2 - it’s very easy to hit invalid utf16 when interacting with web content, and generally text documents with formats or applications dating to the era of ucs2. Whether we consider that to actually matter is a different question - while browsers have to deal with this, I think most modern text APIs simply reject invalid coding and don’t support recovery.
>>
>>
>> This API will substitute replacement characters in that case, so it's at least free of UB or anything bad. Garbage in, garbage out, safely.
>>
>>
Also, thanks for including Alternative 1. I find the name utf_to_utfN
slightly misleading. It seems to imply that it transcodes from one
UTF to another -- which it does -- but it also turns arbitrary garbage
input into nice, shiny UTF-N (with the understanding that the result
may be almost entirely replacement characters). I think the status
quo names are better, especially for naive users.
I would like to change the interpretation of the UTF format of wchar_t
from "based on width" to "implementation defined". Each
implementation knows whether a wchar_t means UTF-16 or UTF-32,
regardless of its width. Not sure if that's a friendly amendment.
I'd also like to see more about the generic case. If I use as_utf32
that recognizes all character types in generic code, as_utf32 is all I
have to write:
// process the code points in the char range R
template<typename R>
auto process_code_points_1(R && r) {
auto cps = r | std::as_utf32;
// do processing here
}
This is incredibly useful, and I use it all over the place in
Boost.Parser. If I have to mention as_charN_t, though:
template<typename R>
auto make_code_points(R && r) {
using char_t = std::ranges::range_value_t<R>;
// The its_charN_ish logic is surprisingly hard to get right
portably, btw (see the paper).
// If I get one of them wrong, I'm advertising UTF-N as UTF-M for
some case below,
// resulting in mojibake that I wouldn't have gotten if the
implementation determines
// which character types correspond to which UTF formats.
if constexpr (its_char8_ish<>)
return r | std::as_char8_t | std::as_utf32;
else if constexpr (its_char16_ish<char_t>)
return r | std::as_char16_t | std::as_utf32;
else if constexpr (its_char32_ish<char_t>)
return r | std::as_char32_t | std::as_utf32;
else
static_assert(!"oopsie");
}
template<typename R>
auto process_code_points_2(R && r) {
auto cps = make_code_points((R &&)r);
// do processing here
}
The punchline? If I write make_code_points() correctly, I get the
same machine code for process_code_points_2() that I would have gotten
for process_code_points_1(). I'm happy to add something like this to
the paper if you like.
Could you explain the rationale for the CHAR_BIT == 8 mandate? Are
people putting UTF-16 or UTF-32 in chars when CHAR_BIT is larger?
Does it matter if they do? We assume that the input is UTF-8 if we're
given char or char8_t input; why should the size of the char matter?
Zach
On Fri, Nov 27, 2026 at 1:15 PM Eddie Nolan <eddiejnolan_at_[hidden]> wrote:
>
> I've written a draft of a paper (D4460R0) that recommends an option aligned with Jonathan's utf_to_utf32 suggestion:
>
> https://docs.google.com/document/d/1S7YuROrepDKqE9HaWMQtl4pMG_zTgelKC6yQ6YhUXWg/edit?usp=sharing
>
> Please take a look and add any suggestions or corrections in a Google Docs comment; or if anyone wants to update the document directly, just request edit access and I'll add you as a coauthor.
>
> One change I made to Jonathan's idea was that, originally, Jonathan suggested that utf_to_utf32 would "dispatch to the appropriate `std::views::as_charXX_t`, followed by `std::views::to_utf32`", but my recommendation instead renames std::views::to_utf32 to std::views::utf_to_utf32 and adds support for char and wchar_t in the view instead of adding an as_char8_t layer. This has the advantages of not increasing the number of range adaptors, and not having .base() give out a transform_view iterator after having written std::string(...) | std::views::utf_to_utf32.
>
> I also added the CHAR_BIT==8 Mandates suggested by Tom Honermann.
>
> Thanks,
>
> Eddie
>
>
> On Sat, Nov 21, 2026 at 7:20 AM Jonathan Wakely <cxx_at_[hidden]> wrote:
>>
>>
>>
>> On Sat, 21 Nov 2026, 10:21 Oliver Hunt via Lib-Ext, <lib-ext_at_[hidden]> wrote:
>>>
>>>
>>>
>>> On Nov 21, 2026, at 1:25 AM, Corentin via Lib-Ext <lib-ext_at_[hidden]> wrote:
>>>
>>>
>>>
>>> On Fri, Nov 20, 2026, 17:16 Eddie Nolan via Lib-Ext <lib-ext_at_[hidden]> wrote:
>>>>
>>>> My thinking was that we would expand the scope of the transcoding range adaptors to interpret char as UTF-8 and wchar_t as UTF-16 or UTF-32 depending on width, and if you want to use any other type you still need to use the casting range adaptors (which we would keep).
>>>>
>>>> I hadn’t thought about the CHAR_BIT thing but the Mandates seems like the right thing to do there.
>>>
>>>
>>> Yup, no point in supporting theorical platforms or invent things not covered by the Unicode standard.
>>>
>>>
>>> One _possible_ concern with interpreting wchar_t as being utf16 rather than ucs2 - it’s very easy to hit invalid utf16 when interacting with web content, and generally text documents with formats or applications dating to the era of ucs2. Whether we consider that to actually matter is a different question - while browsers have to deal with this, I think most modern text APIs simply reject invalid coding and don’t support recovery.
>>
>>
>> This API will substitute replacement characters in that case, so it's at least free of UB or anything bad. Garbage in, garbage out, safely.
>>
>>
Received on 2026-11-27 23:03:46
