[libcxx-commits] [libcxx] [libc++] Mostly Implement P1885R12: `<text_encoding>` (PR #141312)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sat Nov 15 21:59:07 PST 2025


================
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::text_encoding(id) noexcept
+
+#include <algorithm>
+#include <cassert>
+#include <ranges>
+#include <text_encoding>
+#include <type_traits>
+
+#include "../test_text_encoding.h"
+
+using id = std::text_encoding::id;
+
+constexpr void id_ctor(id i, id expect_id, std::string_view expect_name) {
+  std::text_encoding te = std::text_encoding(i);
+
+  assert(te.mib() == expect_id);
+  assert(expect_name == te.name());
+  assert(std::ranges::contains(te.aliases(), expect_name));
+}
+
+constexpr void id_ctors() {
+  for (auto pair : unique_encoding_data) {
+    id_ctor(id(pair.mib), id(pair.mib), pair.name);
+  }
+}
+
+constexpr void test_unknown_other() {
+  {
+    std::text_encoding te = std::text_encoding(id::other);
+
+    assert(te.mib() == id::other);
+    assert(std::string_view("") == te.name());
+    assert(std::ranges::empty(te.aliases()));
+  }
+
+  {
+    std::text_encoding te = std::text_encoding(id::unknown);
+
+    assert(te.mib() == id::unknown);
+    assert(std::string_view("") == te.name());
+    assert(std::ranges::empty(te.aliases()));
+  }
+}
+
+constexpr bool tests() {
----------------
H-G-Hristov wrote:

```suggestion
constexpr bool test() {
```
Nit: The top-level test function is normally just "test()". Can you use consistently: "test()". I think it is sometimes test(); and sometimes tests();

https://github.com/llvm/llvm-project/pull/141312


More information about the libcxx-commits mailing list