Skip to content

Commit

Permalink
[mlir] Move move capture in SparseElementsAttr::getValues
Browse files Browse the repository at this point in the history
This was a TODO for the move to C++14. Now that the move has been completed, we can resolve it.
  • Loading branch information
River707 committed May 11, 2021
1 parent b49a798 commit 731206f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions mlir/include/mlir/IR/BuiltinAttributes.h
Expand Up @@ -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);
}

Expand Down

0 comments on commit 731206f

Please sign in to comment.