P2728R11 — Unicode in the Library, Part 1: UTF Transcoding (13 items) SG-16 Unicode, SG-9 Ranges, LEWG
Eddie Nolan
This paper proposes range adaptor views for transcoding between UTF-8, UTF-16, and UTF-32 encodings in the C++ standard library. It introduces views::to_utf8, views::to_utf16, views::to_utf32, and their _or_error variants that produce std::expected values, along with as_char8_t, as_char16_t, and as_char32_t code unit casting adaptors. Invalid UTF subsequences are handled by substituting U+FFFD replacement characters (per Unicode Substitution of Maximal Subparts) or by yielding typed error values via utf_transcoding_error, providing a safe modern replacement for the deprecated std::codecvt facilities.

References — Anthropic Citations API

[1]
"static_assert((u8"🙂" | views::to_utf32 | ranges::to()) == U"🙂");"
[2]
""The to_utfN_as_error views also use this scheme but produce unexpected values instead of replacement characters.""
[3]
""empty_view>{}""
[4]
""which is that that char8_t corresponds to UTF-8""
[5]
""If the the current input subsequence is the code unit 0xF4""
[6]
""the underlying range could have unbounded compexity""
[7]
""It sets to_increment_ to the number of code units read while decoding c. encodes c into buf_""
[8]
""If the current input subsequence is a code unit between 0xC0 and 0xC2, or between 0xF5 and 0xFF, returns invalid_utf8_leading_byte.""
[9]
""the to_utfN CPOs reject all inputs that are arrays of char, as do the as_charN_t casting CPOs.""
[10]
""If from-type is char8_t:" (multiple occurrences: §24.7.?.6 success() and read()/read-reverse())"
[11]
""struct implicit-cast-to { // exposition only/""
Summary: P2728R11 proposes a set of UTF transcoding range adaptors (to_utf8, to_utf16, to_utf32) and their error-handling variants for the C++ standard library, built on top of std::ranges. It provides views that lazily transcode between UTF-8, UTF-16, and UTF-32, with configurable error handling via expected-based interfaces.
Pipeline: Discovery (Anthropic Opus + Citations API) → Verification Gate (OpenRouter Opus) → Report Writer (OpenRouter Opus)
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.