C++ Logo

sg16

Advanced search

Re: [isocpp-sg16] [isocpp-lib-ext] P2728 Unicode in the Library, Part 1: UTF Transcoding - Convenience alias

From: Eddie Nolan <eddiejnolan_at_[hidden]>
Date: Fri, 27 Nov 2026 14:15:11 -0500
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 19:15:27