From 731206f3684af5979e3a794970db83f9a34b4541 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Tue, 11 May 2021 12:09:17 -0700 Subject: [PATCH] [mlir] Move move capture in SparseElementsAttr::getValues 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mlir/include/mlir/IR/BuiltinAttributes.h b/mlir/include/mlir/IR/BuiltinAttributes.h index 2e6677c12c79c..af75c2e9401a4 100644 --- a/mlir/include/mlir/IR/BuiltinAttributes.h +++ b/mlir/include/mlir/IR/BuiltinAttributes.h @@ -780,15 +780,17 @@ auto SparseElementsAttr::getValues() const auto zeroValue = getZeroValue(); auto valueIt = getValues().getValues().begin(); const std::vector flatSparseIndices(getFlattenedSparseIndices()); - // TODO: Move-capture flatSparseIndices when c++14 is available. - std::function 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 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(0, getNumElements()), mapFn); }