[mlir] Move move capture in SparseElementsAttr::getValues
authorRiver Riddle <riddleriver@gmail.com>
Tue, 11 May 2021 19:09:17 +0000 (12:09 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Tue, 11 May 2021 19:09:42 +0000 (12:09 -0700)
This was a TODO for the move to C++14. Now that the move has been completed, we can resolve it.

mlir/include/mlir/IR/BuiltinAttributes.h

index 2e6677c..af75c2e 100644 (file)
@@ -780,15 +780,17 @@ auto SparseElementsAttr::getValues() const
   auto zeroValue = getZeroValue<T>();
   auto valueIt = getValues().getValues<T>().begin();
   const std::vector<ptrdiff_t> flatSparseIndices(getFlattenedSparseIndices());
-  // TODO: Move-capture flatSparseIndices when c++14 is available.
-  std::function<T(ptrdiff_t)> mapFn = [=](ptrdiff_t index) {
-    // Try to map the current index to one of the sparse indices.
-    for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i)
-      if (flatSparseIndices[i] == index)
-        return *std::next(valueIt, i);
-    // Otherwise, return the zero value.
-    return zeroValue;
-  };
+  std::function<T(ptrdiff_t)> mapFn =
+      [flatSparseIndices{std::move(flatSparseIndices)},
+       valueIt{std::move(valueIt)},
+       zeroValue{std::move(zeroValue)}](ptrdiff_t index) {
+        // Try to map the current index to one of the sparse indices.
+        for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i)
+          if (flatSparseIndices[i] == index)
+            return *std::next(valueIt, i);
+        // Otherwise, return the zero value.
+        return zeroValue;
+      };
   return llvm::map_range(llvm::seq<ptrdiff_t>(0, getNumElements()), mapFn);
 }