[libcxx-commits] [libcxx] [llvm] [libc++] Implement P1885R12: `<text_encoding>` (PR #141312)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jun 3 20:58:38 PDT 2026
================
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <text_encoding>
+
+// REQUIRES: std-at-least-c++26
+// REQUIRES: locale.en_US.UTF-8
+// UNSUPPORTED: no-localization
+// UNSUPPORTED: availability-te-environment-missing
+
+// class locale
+
+// text_encoding locale::encoding() const
+
+#include <cassert>
+#include <format>
+#include <iostream>
+#include <locale>
+#include <text_encoding>
+
+#include "platform_support.h"
+
+int main(int, char**) {
+ {
+ // 1. Locale built with en_US.UTF-8 returns text_encoding representing "UTF-8"
+ const std::locale utf8_locale(LOCALE_en_US_UTF_8);
+ std::text_encoding te = utf8_locale.encoding();
+ std::text_encoding utf8_te = std::text_encoding(std::text_encoding::id::UTF8);
----------------
frederick-vs-ja wrote:
In any case, I don't think it's a good idea to type `std::text_encoding` so many times in this variable definition.
I in this line it would be clearer to use either
- `auto te = std::text_encoding(std::text_encoding::id::UTF8);` or
- `auto te = std::text_encoding{std::text_encoding::id::UTF8};`.
For all similar variable definitions in test files, we may also use
- `std::text_encoding te{std::text_encoding::id::UTF8};`,
- `std::text_encoding te = {std::text_encoding::id::UTF8};`, or
- `std::text_encoding te = std::text_encoding::id::UTF8;`.
Note that `id::` can be omitted as `id` is `using enum`'d. Although it might be clearer to keep it.
https://github.com/llvm/llvm-project/pull/141312
More information about the libcxx-commits
mailing list