[libcxx-commits] [libcxx] [libc++] Add basic constant folding for std::format (PR #107197)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Feb 9 07:19:03 PST 2025
================
@@ -447,10 +449,46 @@ format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) {
}
# endif
+// Try constant folding the format string instead of going through the whole formatting machinery. If there is no
+// constant folding no extra code should be emitted (with optimizations enabled) and the function returns nullopt. When
+// constant folding is successful, the formatting is performed and the resulting string is returned.
+template <class _CharT>
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<basic_string<_CharT>> __try_constant_folding_format(
----------------
mordante wrote:
Please move the code in the `__format` namespace in this header and adjust the function name.
```suggestion
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<basic_string<_CharT>> __try_constant_folding
```
https://github.com/llvm/llvm-project/pull/107197
More information about the libcxx-commits
mailing list