[libcxx-commits] [PATCH] D156022: [NFC][libc++][format] Switches to from_range constructor.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 2 09:02:09 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG7b580d8b40bd: [NFC][libc++][format] Switches to from_range constructor. (authored by Mordante).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156022/new/

https://reviews.llvm.org/D156022

Files:
  libcxx/include/__format/range_default_formatter.h
  libcxx/include/__format/range_formatter.h


Index: libcxx/include/__format/range_formatter.h
===================================================================
--- libcxx/include/__format/range_formatter.h
+++ libcxx/include/__format/range_formatter.h
@@ -28,6 +28,7 @@
 #include <__iterator/back_insert_iterator.h>
 #include <__ranges/concepts.h>
 #include <__ranges/data.h>
+#include <__ranges/from_range.h>
 #include <__ranges/size.h>
 #include <__type_traits/remove_cvref.h>
 #include <string_view>
@@ -184,13 +185,7 @@
       std::formatter<basic_string<_CharT>, _CharT> __formatter;
       if (__debug_format)
         __formatter.set_debug_format();
-      // P2106's from_range has not been implemented yet. Instead use a simple
-      // copy operation.
-      // TODO FMT use basic_string's "from_range" constructor.
-      // return std::formatter<basic_string<_CharT>, _CharT>{}.format(basic_string<_CharT>{from_range, __range}, __ctx);
-      basic_string<_CharT> __str;
-      ranges::copy(__range, back_insert_iterator{__str});
-      return __formatter.format(__str, __ctx);
+      return __formatter.format(basic_string<_CharT>{from_range, __range}, __ctx);
     }
   }
 
Index: libcxx/include/__format/range_default_formatter.h
===================================================================
--- libcxx/include/__format/range_default_formatter.h
+++ libcxx/include/__format/range_default_formatter.h
@@ -24,6 +24,7 @@
 #include <__iterator/back_insert_iterator.h>
 #include <__ranges/concepts.h>
 #include <__ranges/data.h>
+#include <__ranges/from_range.h>
 #include <__ranges/size.h>
 #include <__type_traits/conditional.h>
 #include <__type_traits/remove_cvref.h>
@@ -197,15 +198,8 @@
     // specialization is the "basic" string formatter in libc++.
     if constexpr (ranges::contiguous_range<_Rp> && std::ranges::sized_range<_Rp>)
       return __underlying_.format(basic_string_view<_CharT>{ranges::data(__range), ranges::size(__range)}, __ctx);
-    else {
-      // P2106's from_range has not been implemented yet. Instead use a simple
-      // copy operation.
-      // TODO FMT use basic_string's "from_range" constructor.
-      // return __underlying_.format(basic_string<_CharT>{from_range, __range}, __ctx);
-      basic_string<_CharT> __str;
-      std::ranges::copy(__range, back_insert_iterator{__str});
-      return __underlying_.format(static_cast<basic_string_view<_CharT>>(__str), __ctx);
-    }
+    else
+      return __underlying_.format(basic_string<_CharT>{from_range, __range}, __ctx);
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156022.546499.patch
Type: text/x-patch
Size: 2506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230802/688c9eef/attachment.bin>


More information about the libcxx-commits mailing list