[libcxx-commits] [libcxx] [libc++] Add basic constant folding for std::format (PR #107197)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 12 10:00:54 PDT 2024


================
@@ -463,9 +496,13 @@ template <class = void>
 template <class = void>
 [[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring
 vformat(wstring_view __fmt, wformat_args __args) {
-  wstring __res;
-  std::vformat_to(std::back_inserter(__res), __fmt, __args);
-  return __res;
+  return std::__try_constant_folding(__fmt, __args)
+      .or_else([&]() -> optional<wstring> {
----------------
ldionne wrote:

Did you ensure that storing into an optional and then pulling it out doesn't hurt performance/codegen? Is the move elided in all cases (even though I don't think it's mandated by the language)?

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


More information about the libcxx-commits mailing list