[llvm] [ADT] Use range-based for loops (NFC) (PR #99605)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 21:54:11 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/99605.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/SetOperations.h (+14-19)
``````````diff
diff --git a/llvm/include/llvm/ADT/SetOperations.h b/llvm/include/llvm/ADT/SetOperations.h
index 2b1a103565f7d..40e4b05fd7425 100644
--- a/llvm/include/llvm/ADT/SetOperations.h
+++ b/llvm/include/llvm/ADT/SetOperations.h
@@ -43,9 +43,8 @@ static constexpr bool HasMemberEraseIter =
template <class S1Ty, class S2Ty> bool set_union(S1Ty &S1, const S2Ty &S2) {
bool Changed = false;
- for (typename S2Ty::const_iterator SI = S2.begin(), SE = S2.end(); SI != SE;
- ++SI)
- if (S1.insert(*SI).second)
+ for (const auto &E : S2)
+ if (S1.insert(E).second)
Changed = true;
return Changed;
@@ -73,10 +72,9 @@ template <class S1Ty, class S2Ty> void set_intersect(S1Ty &S1, const S2Ty &S2) {
template <class S1Ty, class S2Ty>
S1Ty set_intersection_impl(const S1Ty &S1, const S2Ty &S2) {
S1Ty Result;
- for (typename S1Ty::const_iterator SI = S1.begin(), SE = S1.end(); SI != SE;
- ++SI)
- if (S2.count(*SI))
- Result.insert(*SI);
+ for (const auto &E : S1)
+ if (S2.count(E))
+ Result.insert(E);
return Result;
}
@@ -94,10 +92,9 @@ S1Ty set_intersection(const S1Ty &S1, const S2Ty &S2) {
template <class S1Ty, class S2Ty>
S1Ty set_difference(const S1Ty &S1, const S2Ty &S2) {
S1Ty Result;
- for (typename S1Ty::const_iterator SI = S1.begin(), SE = S1.end(); SI != SE;
- ++SI)
- if (!S2.count(*SI)) // if the element is not in set2
- Result.insert(*SI);
+ for (const auto &E : S1)
+ if (!S2.count(E)) // if the element is not in set2
+ Result.insert(E);
return Result;
}
@@ -132,9 +129,8 @@ template <class S1Ty, class S2Ty> void set_subtract(S1Ty &S1, const S2Ty &S2) {
}
}
- for (typename S2Ty::const_iterator SI = S2.begin(), SE = S2.end(); SI != SE;
- ++SI)
- S1.erase(*SI);
+ for (const auto &E : S2)
+ S1.erase(E);
}
/// set_subtract(A, B, C, D) - Compute A := A - B, set C to the elements of B
@@ -142,12 +138,11 @@ template <class S1Ty, class S2Ty> void set_subtract(S1Ty &S1, const S2Ty &S2) {
/// from A (B - A).
template <class S1Ty, class S2Ty>
void set_subtract(S1Ty &S1, const S2Ty &S2, S1Ty &Removed, S1Ty &Remaining) {
- for (typename S2Ty::const_iterator SI = S2.begin(), SE = S2.end(); SI != SE;
- ++SI)
- if (S1.erase(*SI))
- Removed.insert(*SI);
+ for (const auto &E : S2)
+ if (S1.erase(E))
+ Removed.insert(E);
else
- Remaining.insert(*SI);
+ Remaining.insert(E);
}
/// set_is_subset(A, B) - Return true iff A in B
``````````
</details>
https://github.com/llvm/llvm-project/pull/99605
More information about the llvm-commits
mailing list