[libcxx-commits] [libcxx] Implement P1885R12: `<text_encoding>` header (PR #141312)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 27 23:29:01 PDT 2025
frederick-vs-ja wrote:
> The issue with `text_encoding::environment()` is that the `text_encoding` class isn't visible in C++23, and I don't see how it would be possible to make it visible prior to C++26 other than:
>
> 1. Backport `<text_encoding>` to C++23
> 2. Wait until libcxx is built with `-std=c++26` by default
>
> I'll have to dig in more with the availability macros, how `<filesystem>` was implemented seems promising.
I think there's another approach. Note that `text_encoding` is a trivially copyable class (although not yet guarantee by the standard), we can define
- a `__text_encoding_rep` class which has the same layout as `text_encoding`, and
- a `__text_encoding_environment_rep` function returning it, and then
- use `std::bit_cast<text_encoding>(__text_encoding_environment_rep())` in `text_encoding::environment`.
The helper class and function can be available in old modes without exposing `text_encoding`. This approach can also make `text_encoding::environment` away from ABI boundary and potentially easier to evolve.
https://github.com/llvm/llvm-project/pull/141312
More information about the libcxx-commits
mailing list