diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
commit | 71d5a2540a98c81f5bcaeb48805e0e2881f530ef (patch) | |
tree | 5343938942df402b49ec7300a1c25a2d4ccd5821 /include/llvm/ADT/GraphTraits.h | |
parent | 31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (diff) |
Diffstat (limited to 'include/llvm/ADT/GraphTraits.h')
-rw-r--r-- | include/llvm/ADT/GraphTraits.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/llvm/ADT/GraphTraits.h b/include/llvm/ADT/GraphTraits.h index 29bbcb010eee..2c88c4271b48 100644 --- a/include/llvm/ADT/GraphTraits.h +++ b/include/llvm/ADT/GraphTraits.h @@ -18,6 +18,8 @@ #ifndef LLVM_ADT_GRAPHTRAITS_H #define LLVM_ADT_GRAPHTRAITS_H +#include "llvm/ADT/iterator_range.h" + namespace llvm { // GraphTraits - This class should be specialized by different graph types... @@ -86,6 +88,33 @@ struct Inverse { // inverse falls back to the original graph. template <class T> struct GraphTraits<Inverse<Inverse<T>>> : GraphTraits<T> {}; +// Provide iterator ranges for the graph traits nodes and children +template <class GraphType> +iterator_range<typename GraphTraits<GraphType>::nodes_iterator> +nodes(const GraphType &G) { + return make_range(GraphTraits<GraphType>::nodes_begin(G), + GraphTraits<GraphType>::nodes_end(G)); +} +template <class GraphType> +iterator_range<typename GraphTraits<Inverse<GraphType>>::nodes_iterator> +inverse_nodes(const GraphType &G) { + return make_range(GraphTraits<Inverse<GraphType>>::nodes_begin(G), + GraphTraits<Inverse<GraphType>>::nodes_end(G)); +} + +template <class GraphType> +iterator_range<typename GraphTraits<GraphType>::ChildIteratorType> +children(const typename GraphTraits<GraphType>::NodeRef &G) { + return make_range(GraphTraits<GraphType>::child_begin(G), + GraphTraits<GraphType>::child_end(G)); +} + +template <class GraphType> +iterator_range<typename GraphTraits<Inverse<GraphType>>::ChildIteratorType> +inverse_children(const typename GraphTraits<GraphType>::NodeRef &G) { + return make_range(GraphTraits<Inverse<GraphType>>::child_begin(G), + GraphTraits<Inverse<GraphType>>::child_end(G)); +} } // End llvm namespace #endif |