[PATCH] D94769: [Support] Format provider improvements
Vladislav Vinogradov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 12 03:20:16 PDT 2021
vinograd47 updated this revision to Diff 378946.
vinograd47 added a comment.
Rebased to re-run pre-commit CI
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
@@ -698,3 +698,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.378946.patch
Type: text/x-patch
Size: 2382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211012/a884f650/attachment.bin>
More information about the llvm-commits
mailing list