[Mlir-commits] [mlir] 2960299 - [ADT] Retire llvm::apply_tuple in favor of C++17 std::apply
Benjamin Kramer
llvmlistbot at llvm.org
Mon Aug 8 09:24:39 PDT 2022
Author: Benjamin Kramer
Date: 2022-08-08T18:23:38+02:00
New Revision: 2960299986980d6070bca6c3e9d8e925e2d8e260
URL: https://github.com/llvm/llvm-project/commit/2960299986980d6070bca6c3e9d8e925e2d8e260
DIFF: https://github.com/llvm/llvm-project/commit/2960299986980d6070bca6c3e9d8e925e2d8e260.diff
LOG: [ADT] Retire llvm::apply_tuple in favor of C++17 std::apply
Added:
Modified:
llvm/include/llvm/ADT/STLExtras.h
llvm/include/llvm/Support/FormatVariadic.h
llvm/unittests/ADT/STLExtrasTest.cpp
llvm/unittests/Support/FormatVariadicTest.cpp
mlir/include/mlir/IR/DialectRegistry.h
mlir/include/mlir/IR/PatternMatch.h
mlir/include/mlir/TableGen/Format.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 0aaefb5e0ee29..8e18b6a95aac0 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -2065,34 +2065,13 @@ template <typename R> detail::enumerator<R> enumerate(R &&TheRange) {
namespace detail {
-template <typename F, typename Tuple, std::size_t... I>
-decltype(auto) apply_tuple_impl(F &&f, Tuple &&t, std::index_sequence<I...>) {
- return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
-}
-
-} // end namespace detail
-
-/// Given an input tuple (a1, a2, ..., an), pass the arguments of the
-/// tuple variadically to f as if by calling f(a1, a2, ..., an) and
-/// return the result.
-template <typename F, typename Tuple>
-decltype(auto) apply_tuple(F &&f, Tuple &&t) {
- using Indices = std::make_index_sequence<
- std::tuple_size<typename std::decay<Tuple>::type>::value>;
-
- return detail::apply_tuple_impl(std::forward<F>(f), std::forward<Tuple>(t),
- Indices{});
-}
-
-namespace detail {
-
template <typename Predicate, typename... Args>
bool all_of_zip_predicate_first(Predicate &&P, Args &&...args) {
auto z = zip(args...);
auto it = z.begin();
auto end = z.end();
while (it != end) {
- if (!apply_tuple([&](auto &&...args) { return P(args...); }, *it))
+ if (!std::apply([&](auto &&...args) { return P(args...); }, *it))
return false;
++it;
}
diff --git a/llvm/include/llvm/Support/FormatVariadic.h b/llvm/include/llvm/Support/FormatVariadic.h
index c1707b4fe9cb9..bc5cd3edf66fe 100644
--- a/llvm/include/llvm/Support/FormatVariadic.h
+++ b/llvm/include/llvm/Support/FormatVariadic.h
@@ -152,7 +152,7 @@ template <typename Tuple> class formatv_object : public formatv_object_base {
formatv_object(StringRef Fmt, Tuple &&Params)
: formatv_object_base(Fmt, ParameterPointers),
Parameters(std::move(Params)) {
- ParameterPointers = apply_tuple(create_adapters(), Parameters);
+ ParameterPointers = std::apply(create_adapters(), Parameters);
}
formatv_object(formatv_object const &rhs) = delete;
@@ -160,7 +160,7 @@ template <typename Tuple> class formatv_object : public formatv_object_base {
formatv_object(formatv_object &&rhs)
: formatv_object_base(std::move(rhs)),
Parameters(std::move(rhs.Parameters)) {
- ParameterPointers = apply_tuple(create_adapters(), Parameters);
+ ParameterPointers = std::apply(create_adapters(), Parameters);
Adapters = ParameterPointers;
}
};
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index f7281f8af0704..bb31b267926f9 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -232,49 +232,6 @@ TEST(STLExtrasTest, EnumerateLifetimeSemanticsLValue) {
EXPECT_EQ(1, Destructors);
}
-TEST(STLExtrasTest, ApplyTuple) {
- auto T = std::make_tuple(1, 3, 7);
- auto U = llvm::apply_tuple(
- [](int A, int B, int C) { return std::make_tuple(A - B, B - C, C - A); },
- T);
-
- EXPECT_EQ(-2, std::get<0>(U));
- EXPECT_EQ(-4, std::get<1>(U));
- EXPECT_EQ(6, std::get<2>(U));
-
- auto V = llvm::apply_tuple(
- [](int A, int B, int C) {
- return std::make_tuple(std::make_pair(A, char('A' + A)),
- std::make_pair(B, char('A' + B)),
- std::make_pair(C, char('A' + C)));
- },
- T);
-
- EXPECT_EQ(std::make_pair(1, 'B'), std::get<0>(V));
- EXPECT_EQ(std::make_pair(3, 'D'), std::get<1>(V));
- EXPECT_EQ(std::make_pair(7, 'H'), std::get<2>(V));
-}
-
-class apply_variadic {
- static int apply_one(int X) { return X + 1; }
- static char apply_one(char C) { return C + 1; }
- static StringRef apply_one(StringRef S) { return S.drop_back(); }
-
-public:
- template <typename... Ts> auto operator()(Ts &&... Items) {
- return std::make_tuple(apply_one(Items)...);
- }
-};
-
-TEST(STLExtrasTest, ApplyTupleVariadic) {
- auto Items = std::make_tuple(1, llvm::StringRef("Test"), 'X');
- auto Values = apply_tuple(apply_variadic(), Items);
-
- EXPECT_EQ(2, std::get<0>(Values));
- EXPECT_EQ("Tes", std::get<1>(Values));
- EXPECT_EQ('Y', std::get<2>(Values));
-}
-
TEST(STLExtrasTest, CountAdaptor) {
std::vector<int> v;
diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp
index 37946165e3651..312b7b14f3b24 100644
--- a/llvm/unittests/Support/FormatVariadicTest.cpp
+++ b/llvm/unittests/Support/FormatVariadicTest.cpp
@@ -536,7 +536,7 @@ TEST(FormatVariadicTest, BigTest) {
"bigint2", "limit", "byte")
<< "\n";
for (auto &Item : Ts) {
- Stream << llvm::apply_tuple(format_tuple(Line), Item) << "\n";
+ Stream << std::apply(format_tuple(Line), Item) << "\n";
}
Stream.flush();
const char *Expected =
diff --git a/mlir/include/mlir/IR/DialectRegistry.h b/mlir/include/mlir/IR/DialectRegistry.h
index 5d2b1c80d6b47..a94d9b35545ab 100644
--- a/mlir/include/mlir/IR/DialectRegistry.h
+++ b/mlir/include/mlir/IR/DialectRegistry.h
@@ -90,9 +90,8 @@ class DialectExtension : public DialectExtensionBase {
unsigned dialectIdx = 0;
auto derivedDialects = std::tuple<DialectsT *...>{
static_cast<DialectsT *>(dialects[dialectIdx++])...};
- llvm::apply_tuple(
- [&](DialectsT *...dialect) { apply(context, dialect...); },
- derivedDialects);
+ std::apply([&](DialectsT *...dialect) { apply(context, dialect...); },
+ derivedDialects);
}
};
diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h
index 200eae8c3b71c..7b0a3be77308d 100644
--- a/mlir/include/mlir/IR/PatternMatch.h
+++ b/mlir/include/mlir/IR/PatternMatch.h
@@ -1131,7 +1131,7 @@ static void processResults(PatternRewriter &rewriter, PDLResultList &results,
auto applyFn = [&](auto &&...args) {
(processResults(rewriter, results, std::move(args)), ...);
};
- llvm::apply_tuple(applyFn, std::move(tuple));
+ std::apply(applyFn, std::move(tuple));
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/TableGen/Format.h b/mlir/include/mlir/TableGen/Format.h
index d2483b358c871..be6b90c838503 100644
--- a/mlir/include/mlir/TableGen/Format.h
+++ b/mlir/include/mlir/TableGen/Format.h
@@ -193,7 +193,7 @@ class FmtObject : public FmtObjectBase {
: FmtObjectBase(fmt, ctx, std::tuple_size<Tuple>::value),
parameters(std::move(params)) {
adapters.reserve(std::tuple_size<Tuple>::value);
- adapters = llvm::apply_tuple(CreateAdapters(), parameters);
+ adapters = std::apply(CreateAdapters(), parameters);
}
FmtObject(FmtObject const &that) = delete;
@@ -201,7 +201,7 @@ class FmtObject : public FmtObjectBase {
FmtObject(FmtObject &&that)
: FmtObjectBase(std::move(that)), parameters(std::move(that.parameters)) {
adapters.reserve(that.adapters.size());
- adapters = llvm::apply_tuple(CreateAdapters(), parameters);
+ adapters = std::apply(CreateAdapters(), parameters);
}
};
More information about the Mlir-commits
mailing list