[PATCH] D94769: [Support] Format provider improvements

Vladislav Vinogradov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 04:56:35 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG791bdba0b183: [Support] Format provider improvements (authored by vinograd47).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94769

Files:
  llvm/include/llvm/Support/FormatProviders.h
  llvm/unittests/Support/FormatVariadicTest.cpp


Index: llvm/unittests/Support/FormatVariadicTest.cpp
===================================================================
--- llvm/unittests/Support/FormatVariadicTest.cpp
+++ llvm/unittests/Support/FormatVariadicTest.cpp
@@ -697,3 +697,31 @@
   EXPECT_EQ("X", formatv("{0}", fmt_consume(std::move(E1))).str());
   EXPECT_FALSE(E1.isA<StringError>()); // consumed
 }
+
+TEST(FormatVariadicTest, FormatFilterRange) {
+  std::vector<int> Vec{0, 1, 2};
+  auto Range = map_range(Vec, [](int V) { return V + 1; });
+  EXPECT_EQ("1, 2, 3", formatv("{0}", Range).str());
+}
+
+namespace {
+
+class IntegerValuesRange final
+    : public indexed_accessor_range<IntegerValuesRange, NoneType, int, int *,
+                                    int> {
+public:
+  using indexed_accessor_range<IntegerValuesRange, NoneType, int, int *,
+                               int>::indexed_accessor_range;
+
+  static int dereference(const NoneType &, ptrdiff_t Index) {
+    return static_cast<int>(Index);
+  }
+};
+
+TEST(FormatVariadicTest, FormatRangeNonRef) {
+  IntegerValuesRange Range(None, 0, 3);
+  EXPECT_EQ("0, 1, 2",
+            formatv("{0}", make_range(Range.begin(), Range.end())).str());
+}
+
+} // namespace
Index: llvm/include/llvm/Support/FormatProviders.h
===================================================================
--- llvm/include/llvm/Support/FormatProviders.h
+++ llvm/include/llvm/Support/FormatProviders.h
@@ -355,7 +355,6 @@
 
 template <typename IterT> class format_provider<llvm::iterator_range<IterT>> {
   using value = typename std::iterator_traits<IterT>::value_type;
-  using reference = typename std::iterator_traits<IterT>::reference;
 
   static StringRef consumeOneOption(StringRef &Style, char Indicator,
                                     StringRef Default) {
@@ -403,15 +402,13 @@
     auto Begin = V.begin();
     auto End = V.end();
     if (Begin != End) {
-      auto Adapter =
-          detail::build_format_adapter(std::forward<reference>(*Begin));
+      auto Adapter = detail::build_format_adapter(*Begin);
       Adapter.format(Stream, ArgStyle);
       ++Begin;
     }
     while (Begin != End) {
       Stream << Sep;
-      auto Adapter =
-          detail::build_format_adapter(std::forward<reference>(*Begin));
+      auto Adapter = detail::build_format_adapter(*Begin);
       Adapter.format(Stream, ArgStyle);
       ++Begin;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94769.474228.patch
Type: text/x-patch
Size: 2382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221109/b17a5cb9/attachment.bin>


More information about the llvm-commits mailing list