Skip to content

Commit 2a0fac5

Browse files
committed
AST: Introduce ProtocolConformance::forEachAssociatedConformance()
1 parent 44838d4 commit 2a0fac5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/swift/AST/ProtocolConformance.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,27 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance
191191
return false;
192192
}
193193

194+
/// Apply the given function object to each associated conformance requirement
195+
/// within this protocol conformance.
196+
///
197+
/// \returns true if the function ever returned true
198+
template<typename F>
199+
bool forEachAssociatedConformance(F f) const {
200+
const ProtocolDecl *protocol = getProtocol();
201+
unsigned index = 0;
202+
for (auto req : protocol->getRequirementSignature().getRequirements()) {
203+
if (req.getKind() != RequirementKind::Conformance)
204+
continue;
205+
206+
if (f(req.getFirstType(), req.getProtocolDecl(), index))
207+
return true;
208+
209+
++index;
210+
}
211+
212+
return false;
213+
}
214+
194215
/// Retrieve the value witness declaration corresponding to the given
195216
/// requirement.
196217
ValueDecl *getWitnessDecl(ValueDecl *requirement) const;

0 commit comments

Comments
 (0)