[libc-commits] [libc] [libc] Template printf_core::Parser to support wchar_t. (PR #222988)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Sep 11 10:52:29 PDT 2026


================
@@ -22,6 +23,22 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace printf_core {
 
+template <typename CharT, char ascii_value> struct CharConstant {};
+
+template <char ascii_value> struct CharConstant<char, ascii_value> {
+  LIBC_INLINE_VAR static constexpr char value = ascii_value;
+};
+
+#if defined(LIBC_TYPES_WCHAR_T_IS_UTF32)
+template <char ascii_value> struct CharConstant<wchar_t, ascii_value> {
+  LIBC_INLINE_VAR static constexpr wchar_t value = ascii_value;
+};
+#endif // LIBC_TYPES_WCHAR_T_IS_UTF32
+
+template <typename CharT, char ascii_value>
+LIBC_INLINE_VAR constexpr CharT char_constant_v =
+    CharConstant<CharT, ascii_value>::value;
----------------
michaelrj-google wrote:

this is a useful concept, it might be useful to put this in `__support/wctype_utils.h` or similar. Can be in a followup though.

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


More information about the libc-commits mailing list