[PATCH] D38806: DepthFirstIterator.h: Use C++11 features to call a completed method onthe set type, instead of requiring that one exists.
Daniel Berlin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 11:22:36 PDT 2017
dberlin updated this revision to Diff 119673.
dberlin marked 2 inline comments as done.
dberlin added a comment.
- Update for review comments
https://reviews.llvm.org/D38806
Files:
include/llvm/ADT/DepthFirstIterator.h
Index: include/llvm/ADT/DepthFirstIterator.h
===================================================================
--- include/llvm/ADT/DepthFirstIterator.h
+++ include/llvm/ADT/DepthFirstIterator.h
@@ -66,17 +66,28 @@
// one more method, completed, which is invoked when all children of a
// node have been processed. It is intended to distinguish of back and
// cross edges in the spanning tree but is not used in the common case.
-template <typename NodeRef, unsigned SmallSize=8>
-struct df_iterator_default_set : public SmallPtrSet<NodeRef, SmallSize> {
- using BaseSet = SmallPtrSet<NodeRef, SmallSize>;
- using iterator = typename BaseSet::iterator;
-
- std::pair<iterator,bool> insert(NodeRef N) { return BaseSet::insert(N); }
- template <typename IterT>
- void insert(IterT Begin, IterT End) { BaseSet::insert(Begin,End); }
+// If completed exists in the set type, it is called.
+template <class NodeRef, unsigned SmallSize = 8>
+using df_iterator_default_set = SmallPtrSet<NodeRef, 8>;
+
+// This lets us detect if the set we've been handed has a completed method we
+// should be calling. The int vs bool argument is to make it prefer one
+// overload over another in the case of ambiguity. bool requires a conversion,
+// the int does not.
+template <typename T, typename NodeRef>
+auto call_completed_method_imp(T &t, NodeRef V, int)
+ -> decltype(t.completed(V), void()) {
+ return t.completed(V);
+}
+template <typename T, typename NodeRef>
+void call_completed_method_imp(T &t, NodeRef V, bool) {
+ return;
+}
- void completed(NodeRef) {}
-};
+template <typename T, typename NodeRef>
+void call_completed_method(T &t, NodeRef V){
+ call_completed_method_imp(t, V, 0);
+}
// Generic Depth First Iterator
template <class GraphT,
@@ -137,7 +148,7 @@
return;
}
}
- this->Visited.completed(Node);
+ call_completed_method(this->Visited, Node);
// Oops, ran out of successors... go up a level on the stack.
VisitStack.pop_back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38806.119673.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171020/27e2536b/attachment.bin>
More information about the llvm-commits
mailing list